I was making a generic method and was wondering if there is some way of adding a constraint to a generic type T
, such that T
has a certain operator, like +, +=, -, -=, etc.
public void TestAdd<T>(T t1, T t2)
{
return t1 + t2;
}
Produces the following error text:
Operator '+' cannot be applied to operands of type 'T' and 'T'
I searched around on Google/SO for a while and couldn't really find anything related.