I have a few basic questions. I see a lot of stuff like below in code:
public class User
{
private IList<Person> _person;
public User()
{
_person = new IList<Person>();
}
public IList<Person> personList
{
get { return _person; }
(protected) set { _person = value; }
}
}
What is the advantage of instantiating the variable in the ctor? Why not instantiate it when declaring? You are instantiating the variable when creating an instance anyway, so why not set it during declaration?
Why set the variable as private and then allow a public property to access it? (I have put protected in brackets, and I can see the advantage of this - allowing only subclasses or itself to set that property), but say you don't have protected or private set. Wouldn't it be better if you just set the variable as public?