Which scenario should I use to change private fields inside class methods / properties:
public class Example { private int intVar = 0; private string stringVar = string.Empty; public int IntVar { get { return this.intvar; } set { this.intvar = value; } } public string StringVar { get { return this.stringVar ; } set { this.stringVar = value; } } private void SomeMethod() {
Maybe this does not matter in this example, but what if someone adds additional code to the properties, and changing the fields through the properties will change some other things?
Can you say which way is better, or does it really not matter?
I know that with C # 3.0 I can write automatically implemented properties, but this is C # 2.0.
source share