How to use LINQ expression to get a subset of data in C#

In the article How LINQ expression is composed LINQ select clause was described. Web developer can change it to get a subset of data. For example, he/she could pull out a list of first name strings like this:

var matches = from client in clients

select client.FirstName;

 

or a list of strings with both first, middle and last names:

 

var matches = from client in clients

select client.FirstName + “  “ + client.MiddleName + “  “ + client.LastName ;

 

Web developer can use standard C# operators on numeric data or strings to modify the information as he/she’s selecting it. This changes the type of collection that’s returned—it’s now an IEnumerable<string> collection of strings, rather than a collection of Client objects.