How can I access the backing variable of an auto-implemented property?

前端 未结 6 1979
逝去的感伤
逝去的感伤 2020-12-23 02:21

In the past we declared properties like this:

public class MyClass
{
    private int _age;

    public int Age
    {
          get{ return _age;  }
                  


        
6条回答
  •  情深已故
    2020-12-23 03:01

    You can't, it's a language feature as opposed to a IDE feature. To be honest i'd prefer then IDE to add the private variable in for you. I agree that it is slightly weird for the class to internally have to use the public entry point to access its own variables. Hence I don't use this new feature that much myself.

提交回复
热议问题