Saturday, May 10, 2008

What is linq ?

Linq is a programing model which is introduced as new concept in the .Net Languages. It is also known as Language Integrated Query. Linq requires some of the extension for the complete support. These extension boosts the productivity also it shortens and gives meaning to syntax for better manipulation


Following is the linq query sample which returns the elements of array in ascending order and are greater then 5
var query = from v in AValues
where v > 5
orderby v ascending
select v;

Now we can retrieve the values from v with the help of the foreach loop in following manner

foreach(int vItem in v)
{
MessageBox.Show(vItem.ToString());
}

now the code of abive query will be converted by the compiler as the following

IEnumerable Query = AValues.Where(v => v > 5)
.OrderBy(v => v).Select(v => v);

No comments: