0

I realized that C# compiles without errors or warning a lambda expression like this:

Func<object> a => () => null;

Besides, while debugging I also noticed that expression run as expected.

Does anyone know why c# compiler does not complain about missing assignment-operator?

Luty
  • 160
  • 3
  • 7
  • I get errors on that; http://rextester.com/live/TWW98796 – doctorlove Nov 22 '16 at 16:04
  • @doctorlove You got error due to .net runtime version. I tested this in 4.6.1 and it worked well. – Luty Nov 22 '16 at 16:05
  • @doctorlove Because that website uses an older compiler. This is C# 6.0 syntax. (The first arrow that is; the second arrow is a lambda-expression arrow) – Dennis_E Nov 22 '16 at 16:06
  • I was trying to flsuh out which version of C# - I should have explicitly asked – doctorlove Nov 22 '16 at 16:07
  • @Dennis_E so there is framework version for which code provided by doctorlove compiles and works? – Evk Nov 22 '16 at 16:17
  • @Evk There's a *language* version for which it will work. You can use it in .NET 1.0 if you want, so long as you have the right C# version. – Servy Nov 22 '16 at 16:19
  • @Servy but in code provided by doctorlove (in first comment) that expression is inside method, so it's not expression bodied member syntax. That's why I ask. – Evk Nov 22 '16 at 16:26
  • @doctorlove I didn't look at his code. Yes, that's just bad code that won't work in any C# version. – Servy Nov 22 '16 at 16:27
  • @Servy, doesn't looks like a duplicated: nowhere is stated it's a property (local variable?), notice two `=>`. – Sinatr Nov 22 '16 at 16:34
  • 1
    @Sinatr It's an expression bodied member where the expression is a lambda. That's the only way that code would compile, so since we know it compiles, that's what it is. – Servy Nov 22 '16 at 16:35
  • 1
    He didn't say the code was inside a method. He said it didn't cause an error, so it must be a expression bodied property. – Dennis_E Nov 22 '16 at 16:36
  • @Servy, good point. From the first look thought it could be something interesting, but it's again about C# 6.0 (soon 7.0). – Sinatr Nov 22 '16 at 16:43
  • @Servy Yes, this is a expression bodied member. Although I have speculated on the operator's missing in the question title, I was actually bothered by the fact that the statement has two lambda operators. I think that's why I did not take the expression bodied member as possible explation for the question. – Luty Nov 22 '16 at 16:50

0 Answers0