9.1 Introduction

Chapter 8 introduced arrays—simple data structures used to store items of a specific type. Although commonly used, arrays have limited capabilities. For instance, you must specify an array’s size when you create it. If, at execution time, you wish to modify that size, you must do so manually by creating a new array and copying elements into it or by using class Array’s Resize method, which performs those tasks for you.

In this chapter, we introduce the .NET Framework’s List collection class—which offers greater capabilities than traditional arrays. A List is similar to an array but provides additional functionality, such as dynamic resizing—a List can increase its size when items are added to it. We use the List collection to implement several data manipulations similar to those in the preceding chapter. List and the .NET Framework’s other collections are reusable, reliable, powerful and efficient and have been carefully designed and tested to ensure correctness and good performance.

Large amounts of data that need to persist beyond an app’s execution are typically stored in a database—an organized collection of data (discussed in Chapter 22). A database management system (DBMS) provides mechanisms for storing, organizing, retrieving and modifying data in a database. A language called SQL (Structured Query Language)—pronounced “sequel”—is the international standard used to perform queries (i.e., to request information that satisfies given criteria) and to manipulate data in relational databases. These organize data in tables that maintain relationships between pieces of data stored in each table—a key goal is to eliminate duplicate data. For years, programs accessing a relational database passed SQL queries to the database management system, then processed the returned results. This chapter introduces C#’s LINQ (Language Integrated Query) capabilities. LINQ allows you to write query expressions, similar to SQL queries, that retrieve information from a variety of data sources, not just databases. In this chapter, we use LINQ to Objects to manipulate objects in memory, such as arrays and Lists.

LINQ Providers

The syntax of LINQ is built into C#, but LINQ queries may be used in many contexts via libraries known as providers. A LINQ provider is a set of classes that implement LINQ operations and enable programs to interact with data sources to perform tasks such as sorting, grouping and filtering elements. Many LINQ providers are more specialized, allowing you to interact with a specific website or data format. Figure 9.1 shows where and how we use LINQ throughout the book.

Fig. 9.1 LINQ usage throughout the book.

Chapter Used to
Chapter 9, Introduction to LINQ and the List Collection Query arrays and Lists.
Chapter 16, Strings and Characters: A Deeper Look Select GUI controls in a Windows Forms app (located in the online section of the chapter).
Chapter 17, Files and Streams Search a directory and manipulate text files.
Chapter 21, Generic Collections; Functional Programming with LINQ/PLINQ Show LINQ method-call syntax with delegates and lambdas. Introduces functional-programming concepts, using LINQ to Objects to write code more concisely and with fewer bugs than programs written with previous techniques. Shows how PLINQ (Parallel LINQ) can improve LINQ to Objects performance substantially with multicore systems.
Chapter 22, Databases and LINQ Query information from a database using LINQ to Entities. Like LINQ to Objects, LINQ to Entities is built into C# and the .NET Framework.
Chapter 23, Asynchronous Programming with async and await Query an XML response from a web service using LINQ to XML. Like LINQ to Objects, LINQ to XML is built into C# and the .NET Framework.
Web App Development with ASP.NET online chapter Retrieve information from a database to be used in a web-based app.
XML and LINQ to XML online chapter Present a more in-depth discussion of querying XML documents using LINQ to XML.
REST Web Services online chapter Query and update a database. Process XML returned by WCF services.

LINQ Query Syntax vs. Method-Call Syntax

There are two LINQ approaches—one uses a SQL-like syntax and the other uses method-call syntax. This chapter shows the simpler SQL-like syntax. In Chapter 21, we’ll show the method-call syntax, introducing the notions of delegates and lambdas—mechanisms that enable you to pass methods to other methods to help them perform their tasks.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset