When to use Linq: for/foreach

Many people around the office love Linq, but I haven’t used it much and hadn’t heard about it until I started here. I have written a few Linq queries (Linq to Objects) but don’t use them extensively in my coding. In the last couple of days I have asked a few people what it is that causes them to go: “Oh! I should use Linq here.”  I got replies like:

“I always use Linq.”
“All the time.”

After pushing a bit harder, someone said that Linq replaces for/foreach loops pretty well. Last night I came up with a pretty nice Linq statement after realizing that I was going to write a foreach loop. Now when I go to write “for” I stop and think if Linq would work better.

What key words trigger the “I should use Linq here” reaction in you?

This entry was posted in C#, Linq. Bookmark the permalink.

One Response to When to use Linq: for/foreach

Comments are closed.