1

I want to overload an operator in a class. I want the overload method to be generic. For example:

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

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

Syntax error, '(' expected

If I remove the generic type parameter, I get the following message at b's type:

The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

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

Sam
  • 40,644
  • 36
  • 176
  • 219
  • See this old post http://stackoverflow.com/questions/756954/arithmetic-operator-overloading-for-a-generic-class-in-c-sharp – Max Mar 13 '13 at 09:36

0 Answers0