Language Integrated Query (LINQ)
Posted by Rajinder
Last Updated: July 22, 2012
  1790

Language Integrated Query is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.

Example 1:

 public void Linq1() 
    { 
        int[] numbers = { 5413986720 }; 
      
        var lowNums = 
            from n in numbers 
            where n < 5 
            select n; 
      
        Console.WriteLine("Numbers < 5:"); 
        foreach (var x in lowNums) 
        { 
            Console.WriteLine(x); 
        } 
    } 
Example 2:
 public void Linq2() 
    { 
        List<Product> products = GetProductList(); 
      
        var soldOutProducts = 
            from p in products 
            where p.UnitsInStock == 0 
            select p; 
      
        Console.WriteLine("Sold out products:"); 
        foreach (var product in soldOutProducts) 
        { 
            Console.WriteLine("{0} is sold out!", product.ProductName); 
        } 
    } 
 
   
  
 
 
   

 
 
Example 1 Result.

Numbers < 5: 




0
 
Great!