Core Operators

A key aspect of becoming comfortable with LINQ is taking advantage of its myriad of available operators. We won't try to provide an exhaustive list, but rather we'll focus on some of the most useful among them.

Any

The operator Any returns a Boolean value and can be used to determine if a sequence is empty or whether it contains a particular predicate.

var firstList = Enumerable.Empty<int>(); var secondList = Enumerable.Range(1,10); Console.WriteLine(     "The first list has members? {0}, The second list has members? {1}",         firstList.Any(), secondList.Any() );

This code returns the following:

The first list has members? False, The second list has members? True

Let's add a second test, as follows:

Console.WriteLine( ...

Get Programming Reactive Extensions and LINQ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.