views:

123

answers:

4

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.

A: 

For me, when I do't have such choice when programing in projects based on .Net 2.0.

J.W.
A: 

Paraphrasing, when:

  • You don't have a collection of some data items
  • You don't want another collection, formed from the original collection, but after some sort of transformation or filtering. This might be sorting, projection, applying a predicate, grouping, etc.

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.

eKek0
+1  A: 

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.

Scott Weinstein
+1  A: 

I agree with the others, namely:

  • No 3.0+
  • Performance not a huge concern

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.

Kyle Rozendo