列舉 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