Language Integrated Query (LINQ)

LINQ Stands for Language-Integrated Query. LINQ has a great power of querying on any source of data, data source could be the collections of objects, database or XML files. We can easily retrieve data from any object that implements the IEnumerable interface. Microsoft basically divides LINQ into three areas and that are give below:

  • LINQ to Object {Queries performed against the in-memory data}
  • LINQ to ADO.Net
    • LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported}
    • LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables}
    • LINQ to Entities {Microsoft ORM solution}
  • LINQ to XML (formerly XLinq) { Queries performed against the XML source}
Example:
int[] nums={0,1,2,3,4,5};
var res = from a in nums
where a < 3
orderby a
select a;
foreach(int i in res)
Console.WriteLine(i);
Output:
0
1
2

2 comments:

Saurabh said...

int[] nums=new int[]{0,1,2,3,4,5}; //Not possible

I think it should be
int[] nums={0,1,2,3,4,5};

and your output is not correct

I think output should be
0
1
2

Kind Regards,
Saurabh

Lakhan Pal Garg said...

Thanks Saurabh for your valuable correction....

Good Job... :)