Serious CS Shu Enum

This section documents enumerated Enum API use.

 

Example:

    public enum UILayer
    {
        BASIC_UI,
        OVERLAY_UI,
        TOP_UI
    }

 

API:Enum.GetValues(typeof(UILayer))

Interpretation: returns an array, the array contents are all enumerated item (not a string) in the UILayer enumeration.

Example:

//Array是数组的基类, 即ary也是数组。它无法实例化
//得到的数组中的枚举项类型为 UILayer,数组类型为 Array
Array ary = Enum.GetValues(typeof(UILayer));

foreach (int i in ary)  //列出枚举项对应的内容
{
    print(i.ToString());
}

for (int i = 0; i < ary.Length; i++)
{
    print(ary.GetValue(i).ToString());  //可以通过(UILayer)ary.GetValue(i)获得枚举项的值
}

 

API:Enum.GetNames(typeof(UILayer))

Interpretation: returns an array, the array content is an enumeration of all entries in the UILayer enumeration (string).

string[] strary = Enum.GetNames(typeof(UILayer));
foreach(string s in strary)
{
    print(s);
}

 

Published 320 original articles · won praise 77 · views 170 000 +

Guess you like

Origin blog.csdn.net/weixin_38239050/article/details/104258402