BCA / B.Tech 9 min read

LINQ | What is LINQ?

LINQ in .NET with C# in Hindi | LINQ in the .NET Framework in Hindi:


  • LINQ is a revolutionary feature of the .NET Framework for simplifying data query and management.
  • It provides developers with better productivity, simpler syntax, and the facility to work with multiple data sources.
  • LINQ has brought a new revolution in the world of data access by overcoming the limitations of ADO.NET.
LINQ in Hindi | What is LINQ?

What is LINQ?

  • LINQ (Language Integrated Query) is a powerful feature in the .NET Framework that provides a simple and uniform way to query data from data sources such as SQL databases, XML, in-memory objects, and others.
  • LINQ was introduced by Microsoft in 2007 with .NET Framework 3.5.
  • Its specialty is that it uses SQL-like syntax in languages like C# and VB.NET to query data.
Why LINQ When We Have ADO.NET in Hindi |  Why do we need LINQ:

  • ADO.NET was already available for data access and management, but LINQ made it simpler and more developer-friendly.
Difference between LINQ and ADO.NET:

  • Simpler Syntax: In ADO.NET, long code had to be written to access and process data. With LINQ, queries can be written and understood in less code.
  • Consistency: LINQ provides the same syntax for different types of data sources (such as XML, databases, in-memory collections).
  • Fewer Bugs: With the use of LINQ, it is easy to catch compile-time errors because it is strongly-typed.
A simple example of LINQ (Sample LINQ Query)

Below is an example of a simple LINQ query:

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        // Using LINQ on an integer array
        int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        // LINQ query
        var evenNumbers = from num in numbers
                          where num % 2 == 0
                          select num;

        // Showing the result
        Console.WriteLine("Even Numbers:");
        foreach (var num in evenNumbers)
        {
            Console.WriteLine(num);
        }
    }
}
Output:

Even Numbers:  
2  
4  
6  
8  

Data Sources in LINQ in Hindi | Data sources in LINQ:

With LINQ, we can work on different types of data sources:

  • LINQ to Objects: In-memory collections like arrays, lists, etc.
  • LINQ to SQL: To query SQL Server databases.
  • LINQ to XML: To work with XML documents.
  • LINQ to Entities: Using the Entity Framework.
  • LINQ to DataSet: To work on ADO.NET DataSet.
Advantages of LINQ in Hindi | Advantage of LINQ:

  • Less code: Less code needs to be written in LINQ.
  • Strong typing: LINQ is strongly-typed, which makes it easy to catch errors early.
  • Simple to read and understand: The syntax of LINQ is similar to SQL, which makes it easy to understand.
  • Diverse data sources: LINQ provides a single interface, which makes it simple to handle different data sources.