What is LINQ?

Easy0-2 Years

What is LINQ?

LINQ (Language Integrated Query) is a feature in C# that provides a unified way to query data from collections, databases, XML, and other data sources using C# syntax.

Advantages

  • Less code
  • Readable syntax
  • Compile-time checking
  • IntelliSense support
  • Type safety

Example

var numbers = new List<int> {1,2,3,4,5};

var result = numbers.Where(x => x > 2);

foreach(var item in result)
{
    Console.WriteLine(item);
}

Interview Tips

  • Introduced in .NET Framework 3.5
  • Supports Query Syntax and Method Syntax