c# - How do I get an enum type as string from one of it's values? -
i'm sure simple, can't figure out.
i return type name of enum passing in 1 of members.
all searches show how member names int values, or display names string values, etc, etc. can't find show me how done.
string name1 = getenumname(colour.black) // should "colour" string name2 = getenumname(flower.daisy) //should "flower" public static string getenumname(enum myenum) { // ...what goes here...? } public enum colour { black, white, pink, blue } public enum flower { pansy, daffodil, daisy }
you can use .gettype().name
.
gettype()
gets type of current instance. , has name
property. keep in mind that, can use .gettype().tostring()
or .gettype().fullname
return namespace+name of type of object.
also don't forget can use is
keyword find out if object specified type or not. f.e:
if(myenum flower)
Comments
Post a Comment