To use it like:
public class myClass <T> where T : IArithmetic
//...
public myFunction(T A, T B){
//...
X = A + B;
//...
}
So, I must somehow overload + operator for the T class.
To use it like:
public class myClass <T> where T : IArithmetic
//...
public myFunction(T A, T B){
//...
X = A + B;
//...
}
So, I must somehow overload + operator for the T class.
This is not possible to create interface for implementing operators.
According to the Standard:
13.2 Interface members
The members of an interface must be methods, properties, events, or indexers. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types, nor can an interface contain static members of any kind.
Can't create this restriction because the operator methods are static so they don't belong to the instance. You can do some runtime check with reflxion and throw a NotSupported excetion if the T type don't support the required operation.