Consider the following code:
var result = IDisposable.Dispose is object; //result equals false
It was surprise for me(and to my colleague that actually drew my attention to it) that this code is compiled.
First my thought was that IDisposable.Dispose
is somehow converted to a compatible delegate
. But then result must be true
since delegate
is compartible with object
, of course.
Looking into the specification I found that method groups have special treating by the compiler(in the context of is operation):
If E is a method group ... the result is false.
Purely out of curiosity, why is it in the spec? Why does the compiler allow it? Why not to throw compile-time error (like for anonymous functions, for instance)?
UPDATE:
- It compiled for me in VS2013 (12.0.21005.1) and .NET 4.5/4.5.1;
- piojo let us know that this code is NOT compiled in Mono(I can't check it myself);
- It is NOT compiled for leppie in VS2015(4.5 or 3.5);
- NOT compiled under VS2013 / 12.0.30501.00 update 2, .NET 4.5.2 target(caramiriel);