csharp convert enum to list
Code Example - csharp convert enum to list
Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();
convert list string to list enum csharp
public static class StringEnumerableExtensions {
public static IEnumerable<T> StringsToEnums<T>( this IEnumerable<string> strs) where T : struct, IConvertible {
Type t = typeof( T );
var ret = new List<T>();
if( t.IsEnum ) {
T outStr;
foreach( var str in strs ) {
if( Enum.TryParse( str, out outStr ) ) {
ret.Add( outStr );
}
}
}
return ret;
}
}
how to make a enum list in csharp
List<Days> days = Enum.GetValues(typeof(Days))
.Cast<Days>()
.ToList();