MattH
MattH

Reputation: 4227

When not to use LINQ To Objects?

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.

Upvotes: 1

Views: 320

Answers (4)

Kyle Rosendo
Kyle Rosendo

Reputation: 25277

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.

Upvotes: 1

Scott Weinstein
Scott Weinstein

Reputation: 19117

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.

Upvotes: 1

eKek0
eKek0

Reputation: 23289

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.

Upvotes: 0

J.W.
J.W.

Reputation: 18181

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

Upvotes: 0

Related Questions