[英]Can I use generic T in an extension method?
Trying to mimic this post: Create Generic method constraining T to an Enum 试图模仿这篇文章: 创建将T约束为枚举的泛型方法
public static string[] ToTextArray(this Dictionary<string, T> dictionary) where T:struct, IConvertible
{
...
}
It appears my T
cannot be resolved. 看来我的
T
无法解决。 What is the correct way to write an extension method for all Dictionary<string, enum_type>
classes? 为所有
Dictionary<string, enum_type>
类编写扩展方法的正确方法是什么?
You're missing the generic type parameter in the method declaration: 您在方法声明中缺少通用类型参数:
public static string[] ToTextArray<T>(this Dictionary<string, T> dictionary)
where T: struct, IConvertible
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.