[FlagsAttribute]
public enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
Run Code Online (Sandbox Code Playgroud)
我有一个enum作为节目.我希望能够得到说Color.Blue在索引2,索引从0开始.我想得到颜色传递的索引号.什么?有人可以给我发一些片段......
Fra*_*ack 11
试试这个:
int index = Array.IndexOf(Enum.GetValues(typeof(Colors )), Colors.Green);
Run Code Online (Sandbox Code Playgroud)