I'm going through a book by Jon Skeet that mentions automatically
implemented properties, but it doesn't do a good job of explaining why
you should bother and what is going on behind the scenes.
For example:
string name;
public string Name
{
get {return name;}
set {name=value;}
}
is the traditional way.
the "new" way (C#3):
public string Name {get; set;}
but what is not clear--is there a variable that's private named 'name'
in the 'new' way? Hidden behind the scenes?
Second, why bother? how does this encapsulate anything? It seems you
can just make Name public and be done with it.
Any help appreciated
RL
implemented properties, but it doesn't do a good job of explaining why
you should bother and what is going on behind the scenes.
For example:
string name;
public string Name
{
get {return name;}
set {name=value;}
}
is the traditional way.
the "new" way (C#3):
public string Name {get; set;}
but what is not clear--is there a variable that's private named 'name'
in the 'new' way? Hidden behind the scenes?
Second, why bother? how does this encapsulate anything? It seems you
can just make Name public and be done with it.
Any help appreciated
RL
Comment