F1 is clearly legal. Is F2? Technically, no. The spec says in section 6.5 that there is a conversion from a lambda expression to a compatible delegate type. Is that a lambda expression? No. It's a parenthesized expression that contains a lambda expression.

The Visual C# compiler makes a small spec violation here and discards the parenthesis for you.

F3 is legal. Is F4? No. Section 7.5.3 states that a parenthesized expression may not contain a method group. Again, for your convenience we violate the specification and allow the conversion.

Third:

enum E { None }
E F5() { return 0; }
E F6() { return (0); }

F5 is legal. Is F6? No. The spec states that there is a conversion from the literal zero to any enumerated type. "(0)" is not the literal zero, it is a parenthesis followed by the literal zero, followed by a parenthesis. We violate the specification here and actually allow any compile time constant expression equal to zero, and not just literal zero.

So in every case, we allow you to get away with it, even though technically doing so is illegal.

@Jason: I believe the spec violations in the first two cases are simply errors that were never caught. The initial binding pass historically has been very aggressive about prematurely optimizing expressions, and one of the consequences of that is that parentheses are thrown away very early, earlier than they ought to be. In pretty much every case, all this does is makes programs that are intuitively obvious work the way they ought to, so I'm not very worried about it. Analysis of the third case is here: blogs.msdn.com/ericlippert/archive/2006/03/28/…
–
Eric LippertFeb 2 '10 at 21:25

5

In theory, in practice, there is a difference (I'm not sure if Mono allows these 3 cases, and don't know of any other C# compilers, so there may or may not be a difference in practice in practice). Violating the C# spec means your code won't be fully portable. Some C# compilers may, unlike Visual C#, not violate the spec in those particular cases.
–
BrianFeb 3 '10 at 15:56

14

@Bruno: All it takes is about eight or ten thousand hours of study of a given subject and you too can be an expert on it. That's easily doable in four years of full-time work.
–
Eric LippertApr 12 '10 at 20:24

23

@Anthony: When I do that I just tell people that my degree is in mathematics, not arithmetic.
–
Eric LippertApr 12 '10 at 23:34

5

In theory, practice and theory are the same but, in pratice they never are.
–
Sayed Ibrahim HashimiSep 23 '10 at 5:46