One Reason I Like LINQ in C#

This is one of my favorite things about LINQ in C#. This code:

var nonBlank = false;

foreach (var byteval in arrayOfBytes)
{
    if (byteval <= 0)
        continue;
    nonBlank = true;
    break;
}

Becomes this code:

var nonBlank = arrayOfBytes.Any(byteval => byteval > 0);
comments powered by Disqus