How can I use a type parameter with operator overloading?

I want to overload the operator in the class. I want the overload method to be common. For instance:

class Subtractable { public static Subtractable operator-<T>(Subtractable a, T b) { //Implementation } } 

When I do this, I get the following message in the generic type parameter:

Syntax error, '(' expected

If I remove the generic type parameter, I get the following message in b type:

Cannot find type name or namespace 'T' (are you missing the using directive or assembly references?)

Is there any way to achieve this? If so, how? If not, why?

+1
source share

Source: https://habr.com/ru/post/977343/


All Articles