When should I NOT use LINQ To Objects?
The inverse of this question has been asked, but didn't cover when not to use L2O.
When should I NOT use LINQ To Objects?
The inverse of this question has been asked, but didn't cover when not to use L2O.
For me, when I do't have such choice when programing in projects based on .Net 2.0.
Paraphrasing, when:
In resume, when you will not manipulate any kind of group of objects. And also, of course, when you don't have c# 3.0 or above.
One reason is when the performance isn't what you need. If the underlying implementation of IEnumerable
doesn't have an indexer, calls to Last(), Skip(), ElementAt()
, etc can result in O(Bad) perf.
I agree with the others, namely:
However one more to add to the list is the fact that it can cause bad coding practices. A simple (and maybe silly) example is using a .Distinct()
method too readily. The same applies in SQL, sometimes shortcuts give bad code, which can lead to unknown and damn hard to locate bugs.
I suppose this can happen with anything, but shortcuts can make it easier to code badly.