I noticed some people declare a private variable and then a public variable with the get and set statements:
private string myvariable = string.Empty;
public string MyVariable
{
get { return myvariable; }
set { myvariable = value ?? string.Empty; }
}
and then some people just do the following:
public string MyVariable
{
get { return value; }
set { MyVariable = value; }
}
Being a bear of little intelligence (yes, I have kids... why do you ask?) I can't figure out why you would choose one over the other. Isn't it just as effective in using a public variable that you can set any time using the set method of the variable?
Can anyone shed some light on this for me?
UPDATE: I corrected the second example after several people pointed out it wouldn't compile. Sorry about that, but the question still remains...