我可以在扩展方法中使用泛型T吗?

Bla*_*ise -1 c# generics enums

试图模仿这篇文章:创建将T限制为枚举的通用方法

public static string[] ToTextArray(this Dictionary<string, T> dictionary) where T:struct, IConvertible
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

看来我T无法解决.为所有Dictionary<string, enum_type>类编写扩展方法的正确方法是什么?

Lua*_*aan 7

您在方法声明中缺少泛型类型参数:

public static string[] ToTextArray<T>(this Dictionary<string, T> dictionary) 
  where T: struct, IConvertible
Run Code Online (Sandbox Code Playgroud)