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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -