It's possible extract values in enum to Char[]?
I have the Enum:
enum eTypeLanguage { typed = 'T', functional = 'F' }
How to extract values eTypeLanguage to Char array?
It's possible extract values in enum to Char[]?
I have the Enum:
enum eTypeLanguage { typed = 'T', functional = 'F' }
How to extract values eTypeLanguage to Char array?
Seems you are looking for this (It returns string[]):
Enum.GetNames(typeof(eTypeLanguage));
//returns: typed, functional
If your are looking for values ('T', 'F') then you may do this (this won't throw System.InvalidCastException for your enum):
var values = Enum.GetValues(typeof(eTypeLanguage))
.Cast<eTypeLanguage>()
.Select(i => (char)i).ToArray();
//returns: 'T', 'F'
If you want to get all enum members' char values, you need to call Enum.GetValues, cast the returned value to the acutal enum type, then cast each member from its enum type to char:
var values = Enum.GetValues(typeof(eTypeLanguage))
.Cast<eTypeLanguage>()
.Select(e => (char)e)
.ToArray();