How to create a property that is enum type

后端 未结 1 1803
臣服心动
臣服心动 2021-01-29 16:04
enum E_Color { red, black };
private E_Color Color
{
    get { return Color; }
    set { Color = value; }
}
public Card(int color, int num)
{
    Color = (E_Color)color;         


        
相关标签:
1条回答
  • 2021-01-29 16:57

    There is no problem with your enum here. The problem is in your property. You are returning the property itself, which causes an infinite loop (Stackoverflow).

    Change it to this:

    private E_Color Color
    {
        get; set;
    }
    

    What you are basically doing is this:

    private E_Color GetColor()
    {
        return GetColor();
    }
    
    0 讨论(0)
提交回复
热议问题