Getting Started

All the examples shown here are based on LINQ to Objects over in-memory data stored in collections. To make the LINQ functionality accessible, you need to make sure to have a reference to System.Core in your project (which is the case by default if you’re targeting .NET Framework 3.5 or later) and to have imported the System.Linq namespace in your code file. To check whether those requirements are met, write the following piece of code:

using System.Linq;...var n = new [] { 1, 2, 3 }.Count();

When doing so, you should see IntelliSense come up when typing the dot preceding the call to the Count method. Figure 19.10 illustrates what you should see if everything is okay. Notice the extension method icon next to the Count method in ...

Get C# 4.0 Unleashed 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.