Stack overflow error in C# - but how to fix it?

前端 未结 5 1189
旧时难觅i
旧时难觅i 2021-01-05 07:50

I\'ve run into a really interesting runtime bug which generates a rogue stack overflow.

I\'ve defined a structure as follows:

public enum EnumDataTy         


        
5条回答
  •  Happy的楠姐
    2021-01-05 08:16

    you have to implemet it with a backing store:

    private EnumDataType dataType;
    public EnumDataType DataType  { get { return EnumDataType.Apple; } set { dataType = value; } }
    

    }

    You should do so anytime you do some acion in the getter and setters. By the way, why can you even set the variables? you can't read them out, you always get EnumDataType.Apple. If you want a start value, you can do like this:

    private EnumDataType dataType = EnumDataType.Apple;
    public EnumDataType
    {
       get
       {
           return dataType;
       }
       set
       {
           dataType = value;
       }
     }
    

提交回复
热议问题