I have read msdn article about properties. They show that example of property:
// Declare a Name property of type string:
public string Name
{
get
{
return myName;
}
set
{
myName = value;
}
}
Then they say:
Once the properties are declared, they can be used as if they were fields of the class.
What would be the difference if they just left:
public string Name;
If I had a field: private string name
and wanted to have only getter? Should I declare
public string GetName(){return name;}
or should use those properties somehow?
Could somebody tell me what is wrong with that example:
private int age;
public void setAge(int age){
if(age < 100)
this.age = age;
}