I use Resharper, and when I make a few lines of code like this:
foreach (var posCombination in possibleCombinations)
{
if (posCombination .Count == combo.Count && posCombination .Select((l, i) => combo.Contains(l)).All(b => b))
{
return true;
}
}
return false;
It will ask me if I want to convert it into a LINQ-expression:
return possibleCombinations.Any(possibleCombination =>
possibleCombination.Count == combo.Count
&& possibleCombination.Select((l, i) => combo.Contains(l)).All(b => b));
I've had a lot of people tell me that they have a hard time reading whats going on in a LINQ statement... So why would I want to convert it to a LINQ-expression, if it makes my code less readable?
This is entirely up to you: if readers of your code, including yourself, prefer a more verbose style, by all means keep it: hard-to-read clever code is much more expensive in programmer's time than in CPU time. After all, it's only ReSharper's hint: paying attention or disregarding it is entirely up to you.
Reading LINQ code would become easier with time (I know it did become much easier for me, but it took considerable amount of writing LINQ code and looking at LINQ code written by other team members). One thing that we found particularly useful was commenting: a LINQ expression can fit a surprising amount of information in a short line of code, so spelling out the intent in plain English helps figuring out the meaning once I stumble upon a line that I wrote a few months ago.