Possible Duplicate:
Solution for overloaded operator constraint in .NET generics
I have the method
public static T Add<T>(T x, T y)
{
return x + y;
}
and I obviosly get a compilation error because maybe the type T does not suppport the operator + . For example if I where to call the method as:
Add<MyCar>(car1, car2);
It will not be possible to call that method because MyCar class does not have a definition for the +
operator.
But it will make sence to call that method as:
Add<Int32>(1,2);
So I remember I read long time ago that I had to place a where clause on the method in order to be able to compile it. It was somethind like:
public static T Add<T>(T x, T y) where T: "implements + operator"
{
return x + y;
}
But I do not remember the syntax.