Accessing members in your own class: use (auto)properties or not?

前端 未结 6 1574
温柔的废话
温柔的废话 2021-01-22 21:16

I\'ve created this \"question\" as a community-wiki, because there is no right or wrong answer. I only would like to know how the community feels about this specific issue.

6条回答
  •  时光说笑
    2021-01-22 21:42

    I don't like prefixing members either, but actually I find I can write something like this accidently and not spot it until run time. Which kinda tempts me to avoid using properties where they're not necessary... but I still do, currently!

    Public String MyString
    {
       { get { return this.MyString; } }  //<== Stack Overflow
       { set { this.myString = value; } } 
    
    }
    private String myString;
    

提交回复
热议问题