/ Published in: C#
This code keeps the code order. For instance:
public enum Color
{
Red = 100,
Green = 0,
Blue = 5
}
-Will generate the names as Red, Green, Blue.
Using the Enum.GetNames approach won't make it.
Expand |
Embed | Plain Text
using System; using System.Linq; using System.Reflection; namespace MyEnum { public class ReflectionUtils { public static string[] GetEnumValues(Type enumType) { return (from fi in enumType.GetFields(BindingFlags.Public | BindingFlags.Static) select fi.Name).ToArray(); } } }
You need to login to post a comment.
