Home>

I think there are fields and properties in the role of member variables in C #, but recently I'm starting to think that only properties are enough.
(Because I'm not so familiar with C #, I may be asking the wrong question.)

The reason is that you can isolate the access level with get or set, and it takes time to replace it with a property later.
(Although it depends on the naming convention, I don't like the variable names being messed up.)

On the contrary, if it is not a field, is there any element that is better than a field?

// so far
private int _age = 0;// field
public int Age {// property
  get {return age;}
  private set {_age = value;}
}
//from now on
public int Age {
  get: get:
  private set;
} = 0;
c#
  • Answer # 1

    Properties only

    Then, even those that are never published are properties
    private int Age {get;set;}
    I think you will write something like that,
    Such a thing as a field
    private int Age;
    I think it's okay.

  • Answer # 2

    See the thread below.

    https://stackoverflow.com/questions/304645