The reciprocal # code between enum, int, string three types:
1 Public enumSex2 { 3man=1,4woman=25 }6 7 Public Static voidEnumconvert ()8 {9 intSexnum = (int) Sex.man;TenConsole.WriteLine ("to convert an enumeration to an integer:"+sexnum);//1 One A stringSexstr =Sex.Woman.ToString (); -Console.WriteLine ("to convert an enumeration to a string:"+sexstr);//"Woman" - theSex sexstrenum = (sex) enum.parse (typeof(Sex),"Mans"); -Console.WriteLine ("to convert a string to an enumeration:"+sexstrenum.tostring ());//"Man" - -Sex sexnumenum = (sex)1; +Console.WriteLine ("converts an integer to an enumeration:"+sexnumenum.tostring ());//"Man" - + stringNumtostr = Enum.getname (typeof(Sex),2); AConsole.WriteLine ("convert an integer to a string:"+numtostr);//"Woman" at - intStrtonum = (int) Enum.parse (typeof(Sex),"Woman"); -Console.WriteLine ("Convert a string to an integer:"+strtonum);//2 -}
#结果:
Willingtolove
————————————————***
C # enum, int, string three types convert to and from each other