小编Hem*_*hna的帖子

为什么具有默认值的枚举在C#中无法正常工作?

我在C#Brain teasers http://www.yoda.arachsys.com/csharp/teasers.html上浏览了Jon skeet网站.为什么项目"Baz"在输出中显示,即使我为枚举中的所有项目声明了默认值

---例如:1

class Test
{

    enum Foo { Bar, Baz,bread, jam };

    const int One = 1;
    const int Une = 1;

    static void Main()
    {
        Foo f = 0;
        Console.WriteLine(f);
        Console.ReadLine();
    }
}
// output :Bar
Run Code Online (Sandbox Code Playgroud)

--eg2

class Test
{
    enum Foo { Bar, Baz,bread=0, jam };

    const int One = 1;
    const int Une = 1;


    static void Main()
    {
        Foo f = 0;
        Console.WriteLine(f);
        Console.ReadLine();
    }
}
//output : Bar
Run Code Online (Sandbox Code Playgroud)

--eg3

class Test …
Run Code Online (Sandbox Code Playgroud)

c# enums c#-4.0

5
推荐指数
1
解决办法
166
查看次数

标签 统计

c# ×1

c#-4.0 ×1

enums ×1