Answers for "c# how to convert list to enum"

C#
3

c# convert enum to list

Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();
Posted by: Guest on December-03-2020
0

convert list string to list enum c#

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;
    }
}
Posted by: Guest on December-29-2020

C# Answers by Framework

Browse Popular Code Answers by Language