c# - 为多个类型参数添加类型限制?

标签 c# extension-methods

我有一个扩展方法

public static bool Between<T1, T2>(this T1 Foo, T2 bar) where T1: IComparable
{
     //Body
}

如何限制我的 EM,以便 T1: IComparable 和 T2: IConvertible

我试过了

T1: IComparable, T2: IConvertible

但给出错误。那怎么写呢?

最佳答案

试试这个:

 where T1: IComparable where T2: IConvertible

有关类型参数约束的更多信息,请查看此处:
http://msdn.microsoft.com/en-us/library/d5x73970.aspx

关于c# - 为多个类型参数添加类型限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10511602/

相关文章:

c# - 对 SqlCommand 的扩展方法进行单元测试的方法

c# - 扩展方法和本地 'this' 变量

asp.net-mvc - 自定义 HtmlHelper 扩展方法在 View 中不可用?

c# - C# 中的类设计 - DAL

c# - 下拉列表无法识别列表项

c# - 将默认数据库设置为用户 SQL Server (Azure)

c# - 对于封装和可重用性,首选扩展方法?

c# - 如何从日期列中排除时间

c# - Parallel.ForEach 和 DataGridViewRow

.net - 使用 SustainSys Saml2 扩展方法 ToHttpRequestData 编译错误 "call is ambiguous"