Tuesday, September 20, 2011

LINQ queries


LINQ popularly known as Language Integrated Query. LINQ language is one of the major advancement in .Net framework and is used for writing type-safe queries over object collections. LINQ was introduced in C# 3.0 and Framework 3.5.



In simple terms a basic unit of data in LINQ are called as sequence and elements.
Following example can explain these terms:


string[] place = { "Bangalore", "Pune", "Mumbai" };


In the above example, place is a sequence,and Bangalore, Pune and Mumbai are elements.


In the System.Linq class, there are around 40 query operators which are implemented as static extension methods.A query operator accepts an input sequence and generates output sequence.


For example:- Where operator can be used to extract cities with at least four characters length


string[] place = { "Bangalore", "Pune", "Mumbai" };
IEnumerable filteredPlace = place.Where(n=> n.Length>=4);


Output:-
Bangalore
Mumbai

No comments :

Post a Comment