Chapter 7. Introduction to LINQ
After completing this chapter, you will be able to
Understand what LINQ is.
Write LINQ queries against collection classes.
What Is LINQ?
In the previous chapters, you saw how to create and interact with collections using the foreach statement and Microsoft .NET interfaces. In this chapter, you will discover a different approach: how to query your collections with the Language Integrated Query (LINQ). With LINQ, you can query data by using native language syntax.
Here’s an example that does not use LINQ.
C#
Random rnd = new Random(); List<int> randomNumbers = new List<int>(); for (int i = 0; i < 10; i++) { randomNumbers.Add(rnd.Next(100)); } List<int> sortedNumbers = new List<int>(randomNumbers); sortedNumbers.Sort(); sortedNumbers.Reverse(); ...
Get Developer’s Guide to Collections in Microsoft® .NET 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.