【发布时间】:2014-01-01 13:47:05
【问题描述】:
我需要使用一个通用方法来减去两个操作数,就像这样,带有一些伪编码。
public double GetResult<T>(T Arg1, T Arg2) : where T contains "-" operator
{
return Arg1 - Arg2;
//No, they are not value types, they are classes implementing the "-" operator
//And eventually, they can be value types
}
这可能吗?就像有一个 where T = new() 用于创建者的类型一样,是否有一个 where T contains "-" operator?
【问题讨论】:
-
不,不可能在 C# 中编写这样的约束。