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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.