3

I need to use a generic method that subtracts the two operands, like this, with some pseudo coding.

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
}

Is that possible? Like there is a where T = new() for types with creators, is there a where T contains "-" operator?

Daniel Möller
  • 84,878
  • 18
  • 192
  • 214

1 Answers1

2

The library at http://www.yoda.arachsys.com/csharp/miscutil/ contains classes for performing math operations on generic arguments.

William
  • 1,867
  • 11
  • 10