📌  相关文章
📜  将列表字符串转换为列表枚举c#代码示例

📅  最后修改于: 2022-03-11 14:49:07.792000             🧑  作者: Mango

代码示例1
public static class StringEnumerableExtensions {
    public static IEnumerable StringsToEnums( this IEnumerable strs) where T : struct, IConvertible {
        Type t = typeof( T );

        var ret = new List();

        if( t.IsEnum ) {
            T outStr;
            foreach( var str in strs ) {
                if( Enum.TryParse( str, out outStr ) ) {
                    ret.Add( outStr );
                }
            }
        }

        return ret;
    }
}