Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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;
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #convert #list #string #list #enum
ADD COMMENT
Topic
Name
3+2 =