Original Post
While reading about C# I came upon these Properties that seem to me like they are a simple way of hiding the get/set methods to access and modify variables inside a class and I wanted to know if they had any real advantages over the classical method. so would it be better to do this OR This Thanks for your reply !!
private string foreName;
public string ForeName
{
get
{
return foreName;
}
set
{
if (value.Length > 20)
// code here to take error recovery action
// (eg. throw an exception)
else
foreName = value;
}
}
private string foreName;
public void getForeName()
{
return foreName;
}
public void setForeName(String name)
{
foreName = name;//with more code if needed
}