dotnet / csharpstandard

Working space for ECMA-TC49-TG2, the C# standard committee.
Creative Commons Attribution 4.0 International
720 stars 86 forks source link

12.11.9 Delegate equality operators #93

Open marek-safar opened 9 years ago

marek-safar commented 9 years ago
using System;

class X
{
    public static void Main ()
    {
        Action a = null;
        bool res = a == Main; // ok

        bool res1 = a == delegate {}; // Not allowed only method groups can do it
        bool res2 = a == Foo;  // Fails to bind
    }

    static int Foo ()
    {
        return 1;
    }
}

Perhaps we need subsection here to describe method-group specific extension to delegate equality comparisons.

I don't know what was intended purpose of this but C# compiler allows to compare delegates and method groups when one side is a delegate and other side is a method group which can be converted to this delegate. Because method-group is never null the result is actually identical to delegate instance comparison to not-null.

jskeet commented 6 years ago

All comments prior to this one were before we removed section 7. I've updated the title only.

jskeet commented 3 years ago

(I think this is a bug rather than a clarity matter, but it needs further investigation before I'd be certain.)