110,477
社区成员
发帖
与我相关
我的任务
分享
public T MyAlgorithm<T>(T x, T y)
{
return x * x + y * y //No!!不让我使用*运算符
}
public T MyAlgorithm<T>(T x, T y) where T : struct, IConvertible
{
if (typeof(T) == typeof(DateTime)) //手动排除不可运算的值类型...
{
throw new ArgumentException("T");
}
return x + y; //或者使用 IConvertible 辅助处理...
}
Return x * x + y * y