Tutorial :Examples on when not to use LINQ


This is sort of a follow up on this question I read: 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?


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


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.


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.


It's still okay to use foreach. :)

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »