Access to non-static enumeration values ​​from static methods

public enum sEnum
{
    zero = 0, one = 1
}

public int x;

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

Why can the values ​​of this enum be checked here since the static keyword is not used? Where is this specified in the language specification?

+3
source share
2 answers

Enumerations are only named values, so you can use them in a static context, like any other constant.

Section 3.4.3 of the language specification states:

Enumeration Elements are Constants Declared in an Enumeration

+6
source

I think 14.3 in the specs is what you are looking for:

enum , . - . . . Enum - , .

+2

Source: https://habr.com/ru/post/1764207/


All Articles