Possible to overload null-coalescing operator?

Good question! It’s not listed one way or another in the list of overloadable and non-overloadable operators and nothing’s mentioned on the operator’s page.

So I tried the following:

public class TestClass
{
    public static TestClass operator ??(TestClass  test1, TestClass test2)
    {
        return test1;
    }
}

and I get the error “Overloadable binary operator expected”. So I’d say the answer is, as of .NET 3.5, a no.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)