The example Use reflection to list the values defined by an enum in C# shows one way to list the values defined by an enumerated type. That method is flexible but somewhat awkward.
This example uses the first technique to display a list of enumerated values. Instead of getting the enum‘s type object and then digging through its fields to find those that are literals, this example uses the Enum class’s GetValues method to list the values defined by an enumeration. The GetValues method returns an array of values that the program can display by setting a ListBox‘s DataSource property.
This lets the program display the list with this single line of code:
lstValues.DataSource = Enum.GetValues(typeof(HatchStyle));
This is less flexible than the technique used by the previous example, but it’s much easier if you only want to list the values.