O'Reilly logo

Programming Reactive Extensions and LINQ by Paul Betts, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required