/ Published in: C#
<p>This code keeps the code order. For instance:</p>
<pre><code>public enum Color
{
Red = 100,
Green = 0,
Blue = 5
}
</code></pre>
<p>-Will generate the names as Red, Green, Blue.
Using the <code>Enum.GetNames</code> approach won't make it.</p>
<pre><code>public enum Color
{
Red = 100,
Green = 0,
Blue = 5
}
</code></pre>
<p>-Will generate the names as Red, Green, Blue.
Using the <code>Enum.GetNames</code> approach won't make it.</p>
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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(); } } }