试图模仿这篇文章:Create Generic method constraining T to an Enum
public static string[] ToTextArray(this Dictionary<string, T> dictionary) where T:struct, IConvertible
{
...
}
看来我的T
无法解析。为所有Dictionary<string, enum_type>
类编写扩展方法的正确方法是什么?
答案 0 :(得分:7)
您在方法声明中缺少泛型类型参数:
public static string[] ToTextArray<T>(this Dictionary<string, T> dictionary)
where T: struct, IConvertible