Why must C# operator overloads be static?

This has been answered in excruciating detail by Eric Lippert in a blog post that has since been removed. Here is the archived version.

There is also another subtler point about value types and instance operators. Static operators make this kind of code possible:

class Blah {

    int m_iVal;

    public static Blah operator+ (Blah l, int intVal)
    {
        if(l == null)
            l = new Blah();
        l.m_iVal += intVal;
        return l;
    }
}

//main
Blah b = null;
b = b + 5;

So you can invoke the operator, even though the reference is null. This wouldn’t be the case for instance operators.

Leave a Comment