0

Kind of an objective question which could possibly go into one of the other sites but Im not sure so Im asking here!

What are the advantages and disadvantages of using lambda notation as opposed to the more "sql like" notation? personally I prefer the "sql like" method due to readablility but do they both compile to the same IL? is there any performance difference? are the treated any differently by the compiler?

eg.

Foo.Where(Bar => Bar.Stuff == "SomeString")

VS

from Foo in Bar
where Bar.Stuff == "SomeString"
select Foo
rae1
  • 6,066
  • 4
  • 27
  • 48
Steven Wood
  • 2,675
  • 3
  • 26
  • 51
  • 3
    Yes, they are both compile to the same IL. – rae1 Jan 13 '14 at 15:17
  • 1
    Your query doesn't make much sense to me. I assume you mean this: `from bar in Foo where bar.Stuff=="SomeString" select bar`. At least that would be the same as the first query´. – Tim Schmelter Jan 13 '14 at 15:20

1 Answers1

2

No actually. There is no performance difference.These are same:

from Foo in Bar
where Bar.Stuff == "SomeString"
select Foo

Foo.Where(Bar => Bar.Stuff == "SomeString")

First statement converting to second by compiler behind the scenes.Which one is easy to you,use it.

Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • Thanks ill set as the answer when the time expires – Steven Wood Jan 13 '14 at 15:20
  • @statue Don't edit my answer like that! if you want to say something different write your own answer – Selman Genç Jan 13 '14 at 15:33
  • I was honestly trying to translate your answer. Your English makes little sense to me (the last line at least), and I thought that's what you intended. – Stachu Jan 13 '14 at 15:36
  • @statue that is not the point of editing.If there is grammar mistake you can fix it,but you can't change all of my words – Selman Genç Jan 13 '14 at 15:40
  • I added one (constructive) opinion in. I left all of your opinions there. I fixed your grammar so it made sense. The opinion could have been in another answer, but I felt it quite useful to the OP, and it did not deserve its own space. – Stachu Jan 13 '14 at 16:20