http://www.c-sharpcorner.com/UploadFile/ggaganesh/EncapsulationInCS11082005064310AM/EncapsulationInCS.aspx
C# provides accessor methods (get and set methods) which are used to achieve the encapsulation in the C#.
There are two ways of encapsulating or hiding the data.
1. CREATING METHODS TO HIDE DATA
public class LogInToken
{
private string Name;
public string GetName()
{
return Name;
}
public string SetName(string s)
{
Name=s;
}
}
2. USING PROPERTIES TO HIDE DATA
public class LogInToken
{
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value; // C# uses the implicit parameter "value"
}
}
}
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment