.NET API Documentation

System.Linq Namespace

Namespace: System

Assembly: System.Linq.dll

Provides classes and interfaces that support programmers in implementing Language-Integrated Query (LINQ).

Classes

Interfaces

Common LINQ Operations

The System.Linq namespace enables powerful data querying capabilities in .NET. Some of the most common operations include:

Example: Filtering and Selecting


using System;
using System.Collections.Generic;
using System.Linq;

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}

public class Example
{
    public static void Main(string[] args)
    {
        List<Product> products = new List<Product>
        {
            new Product { Id = 1, Name = "Laptop", Price = 1200.00m },
            new Product { Id = 2, Name = "Mouse", Price = 25.50m },
            new Product { Id = 3, Name = "Keyboard", Price = 75.00m },
            new Product { Id = 4, Name = "Monitor", Price = 300.00m }
        };

        // Get names of products with a price greater than 100.00
        var expensiveProductNames = products
            .Where(p => p.Price > 100.00m)
            .Select(p => p.Name);

        Console.WriteLine("Expensive Product Names:");
        foreach (var name in expensiveProductNames)
        {
            Console.WriteLine(name);
        }
    }
}