Friday, 6 January 2017

c# - How to find out all possible values of an enum?










Say I have an enum type MyEnum. Is there a way in C# to get a list of all possible values for an enum of type MyEnum?


Answer



An instance of the enum can have any assignable to the underlying type (i.e., int.MinValue through int.MaxValue for any regular enum). You can get a list of the named values by calling Enum.GetNames and Enum.GetValues.



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...