C# LINQ

C# LINQ

LINQ (Language Integrated Query) is a powerful feature of .NET that allows you to query data from various sources, including databases, XML, JSON, objects, and more, using a single, consistent syntax. It provides a declarative way to work with data, making your code more readable and maintainable.

Example: Querying an Array

                    
using System;
using System.Linq;

public class Example
{
    public static void Main(string[] args)
    {
        int[] numbers = { 1, 2, 3, 4, 5 };

        // Query the array to get all even numbers
        var evenNumbers = numbers.Where(n => n % 2 == 0);

        foreach (int number in evenNumbers)
        {
            Console.WriteLine(number);
        }
    }
}
                    
                

This example demonstrates how to use the Where extension method to filter the array based on a condition.