I'm a new programmer, so please forgive any dumbness of this question but can anyone please tell me how the folowing code is encapsulating private data-
public class SomeClass
{
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
public SomeClass(int age)
{
this.age = age;
}
}
I mean, with no restriction logic or filtering logic in the properties, how is the above code different from the folowing one -
public class SomeClass
{
public int age;
public SomeClass(int age)
{
this.age = age;
}
}
Is the first code providing any encapsulation at all?