tags:

views:

279

answers:

4

This is sort of a follow up on this question I read: http://stackoverflow.com/questions/777400/what-is-the-biggest-mistake-people-make-when-starting-to-use-linq

The top answer is "That it should be used for everything." That made me wonder what exactly that means.

What are some common examples where someone used LINQ when they should not have?

+2  A: 

I would suggest avoiding LINQ anytime it made the code less obvious.

However, in general, I think LINQ makes things easier to follow, not more difficult, so I rarely avoid it.

Reed Copsey
Less obvious to whom?
le dorfier
@Reed: good point, totally agree.
andy
+4  A: 

You shouldn't use LINQ when the alternative is simpler or significantly more efficient.

JaredPar
an example? LINQ is quite specific so you can't, and wouldn't, use it for anything and everything. I find it generally makes things simpler.As for efficiency then yes, its easy to perform more efficiently without LINQ. And you're right, only when it is SIGNIFICANT...good point
andy
A: 

It is possible for LINQ to be significantly slower than the alternatives, especially if you have a lot of intermediate Lists. However you are talking about some pretty large datasets, so large that I haven't encountered them.

However, one thing to keep in mind is that a well-written LINQ query can also be much faster than the alternative because of the way IEnumerable works.

Finally, using LINQ now will allow you to switch to Parallel LINQ when it is released with little or no changes.

Jonathan Allen
A: 

It's still okay to use foreach. :)

JP Alioto