Accessing non-static enum values from static methods

后端 未结 2 811
离开以前
离开以前 2021-01-13 22:41
public enum sEnum
{
    zero = 0, one = 1
}

public int x;

public static void a(sEnum s)
{
    x = 3;
    if (s == sEnum.one) ...
}

Why can values

2条回答
  •  盖世英雄少女心
    2021-01-13 23:22

    Enums are just named values so you can use them in a static context just like any other constant.

    Section 3.4.3 of the language specification states:

    The members of an enumeration are the constants declared in the enumeration

提交回复
热议问题