dotnet / dotnet/csharpstandard

12.11.9 Delegate equality operators

Open
#93 2 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

```
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.