O'Reilly logo

Visual C#® 2012: How to Program, Fifth Edition by Harvey Deitel, Paul Deitel

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

9.3. Querying an Array of Employee Objects Using LINQ

LINQ is not limited to querying arrays of simple types such as ints. It can be used with most data types, including strings and user-defined classes. It cannot be used when a query does not have a defined meaning—for example, you cannot use orderby on objects that are not comparable. Comparable types in .NET are those that implement the IComparable interface, which is discussed in Section 20.4. All built-in types, such as string, int and double implement IComparable. Figure 9.3 presents the Employee class. Figure 9.4 uses LINQ to query an array of Employee objects.

 1   // Fig. 9.3: Employee.cs  2   // Employee class with FirstName, LastName and MonthlySalary ...

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