Is there any difference between the two pieces of code below? Or is the top just a short form of the bottom one?
public string Name { get; set; }
and
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
The only difference (other than the fact you would have to do the initialization with “Default Name” in your class constructor) is that
_Namewill be visible within the class itself. There’s a risk that the class will internally reference_Namerather thanName, everything will work fine, and at some later point in time you’ll add some logic toNamethat will not be called because you’re using_Namewithin the class.Example: