Editorials

Linq or For

I have been using ReSharper from Jet Brains for years. This isn’t a promotion for ReSharper. One thing about the tool is that it provides for you optimization hints for how you write your code.

On thing I have noticed that it does is prompt you to modify all for type loops into Linq queries. I’m wondering if that really is always a best practice. I have noticed that if I have something really complicated going on, it is a lot easier to debug with loops than with the Linq syntax because you can’t step through a Linq statement.

I do like the Linq syntax however, especially when you get nested actions. Using for loops it is easy for the code to get so long that you can’t really see what is going on. However, again in Linq statements you may not see the underlying load that may occur.

One thing for sure, your Linq queries if not written correctly are going to be a lot slower than for loops. So, be sure to follow up on that topic if you are having performance problems with your Linq queries.

So what’s the consensus…do we use one over the other? Do we use both methods? If we use both techniques, how do you choose one over the other? One thing is for sure, using Linq will help you perfect your use of lambda expressions.

Share your thoughts here online or by Email to btaylor@sswug.org.

Cheers,

Ben