这可能吗?
public interface Foo<TBar>
where TBar : (can use the '+' and '-' operators)
Run Code Online (Sandbox Code Playgroud)
谢谢.
我没有使用泛型,因此无法弄清楚是否可以使用泛型将以下三种方法合并为一种以减少重复.实际上我的代码目前有六种方法,但如果你可以解决这三种方法,那么其余的应该只使用相同的解决方案.
private object EvaluateUInt64(UInt64 x, UInt64 y)
{
switch (Operation)
{
case BinaryOp.Add:
return x + y;
case BinaryOp.Subtract:
return x - y;
case BinaryOp.Multiply:
return x * y;
case BinaryOp.Divide:
return x / y;
case BinaryOp.Remainder:
return x % y;
default:
throw new ApplicationException("error");
}
}
private object EvaluateFloat(float x, float y)
{
switch(Operation)
{
case BinaryOp.Add:
return x + y;
case BinaryOp.Subtract:
return x - y;
case BinaryOp.Multiply:
return x * y;
case BinaryOp.Divide:
return x / y; …Run Code Online (Sandbox Code Playgroud)