LINQ
LINQ
What is LINQ
LINQ stands for "Language Integrated Query”.
It enables us to query the data from the various data sources like SQL
databases, XML documents, ADO.NET Datasets, Web services and any
other objects such as Collections, Generics etc.
using a SQL Query like syntax with .NET framework languages like C#
and VB.NET.
Advantages of LINQ
Writing
codes is quite faster in LINQ and thus
development time also gets reduced significantly.
select n; //selection
}
}
// Output: 4 5 8 9
using System;
//Step2: Query
using System.Collections.Generic;
//LINQ Query using Query Syntax
using System.Linq;
to fetch all numbers which are > 5
namespace LINQDemo
var res = integerList.Where(x=x>
{
5).ToList();
class Program
{
//Step3: Execution
static void Main(string[] args) foreach (var item in res)
{ {
//Step1: Data Source Console.Write(item + " ");
List<int> integerList = new List<int>() }
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
}; }
}
string[] names = {"Bill", "Steve", "James", "Mohan" };
// LINQ Query
// Query execution
There are two syntaxes of LINQ. These are the following ones.