枚举 ZERO 的默认值

枚举的默认值为零。如果枚举未定义值为零的项,则其默认值将为零。

public class Program
{        
    enum EnumExample
    {
        one = 1,
        two = 2
    }
    
    public void Main()
    {              
        var e = default(EnumExample);
        
        if (e == EnumExample.one)
            Console.WriteLine("defaults to one");
        else
            Console.WriteLine("Unknown");    
    }    
}

示例: https//dotnetfiddle.net/l5Rwie