C# Linq Select

Authors

Introduction LINQ Select

LINQ (Language Integrated Query) is a powerful tool in C# for querying data from collections and databases. The Select operator is one of the commonly used LINQ operators that allows you to project the results of a query into a new form. The Select operator is used to transform each element in the source collection by applying a specified projection.

Here is an example of using the Select operator to transform a list of strings into a list of their lengths:

Query Syntax

List<string> words = new List<string> {"apple", "banana", "mango"};

// Transform the list of words into a list of their lengths
var wordLengths = words.Select(word => word.Length);

// Output the resulting list of lengths
foreach (var length in wordLengths)
{
    Console.WriteLine(length);
}
TrackingJoy