Page Stats
Visitor: 195
C#.Net Properties
Properties is use to access the private fields to read or write their values. A property consists of a get or set declaration, or both. A property can be read-write property, read-only property, or a write only property, according to the presence or absence of the get and set accessors. If both are present the property is read-write property. If only get is present it’s a read only property. And if only set is present it’s a write-only property.
The get is a parameter less method with a return value, and use to invoke the value of a private field to compute.
The set is use to assign a value of a private field.
class ex { private int rollno; public int RollNo { get { return rollno; } set { rollno = value; } } } class Program { static void Main(string[] args) { ex obj = new ex(); obj.RollNo = 100; Console.WriteLine("Rollno=" + obj.RollNo); Console.Read(); } }