How to get an array of all enum values in C#? -


i have enum i'd display possible values of. there way array or list of possible values of enum instead of manually creating such list? e.g. if have enum:

public enum enumnum { typea, typeb, typec, typed } 

how able list<enumnum> contains { typea, typeb, typec, typed }?

this gets plain array of enum values using enum.getvalues:

var valuesasarray = enum.getvalues(typeof(enumnum)); 

and gets generic list:

var valuesaslist = enum.getvalues(typeof(enumnum)).cast<enumnum>().tolist(); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -