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
Post a Comment