If a property has only get
accessor we call it read-only property.
The following code add read-only area
property to the Rectangle.
using System;
class Rectangle
{
public int Width;
public int Height;
public int Area
{
get
{
return Width * Height;
}
}
}
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.Width = 5;
r.Height = 6;
Console.WriteLine(r.Area);
}
}
The output:
30
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |