Why doesn't the C# compiler stop properties from referring to themselves?

后端 未结 6 2101
灰色年华
灰色年华 2020-12-05 17:38

If I do this I get a System.StackOverflowException:

private string abc = \"\";
public string Abc
{
    get
    { 
        return Abc; // Note th         


        
6条回答
  •  再見小時候
    2020-12-05 17:40

    They probably considered it would unnecessary complicate the compiler without any real gain.

    You will discover this typo easily the first time you call this property.

提交回复
热议问题