|
|||||
|
It is a common practice among developers to design components which have properties. C# has made it very simple to use properties. Properties are accessor methods whose job it is to retrieve and set the values of fields. It provides a way to protect a field in a class by reading and writing and also a way to support object-oriented concept of encapsulation. For example, take a look at the following code: public class University {
private string univName;
public string univID
{
get
{
return univName;
}
set
{
univName = value;
}
}
}
To use the property : University myUniv = new University(); myUniv.univID = "rice"; string name = myUniv.univID; Note that value is a special value which represents the value passed in from the user .value has the type of the property in context. |