Friday, June 18, 2010

Take,Skip and Reverse Operator in Linq

I have found three more new operators in Linq which is use full in day to day programming stuff. Take,Skip and Reverse. Here are explanation of operators how it works.

Take Operator: Take operator will return first N number of element from entities.

Skip Operator: Skip operator will skip N number of element from entities and then return remaining elements as a result.

Reverse Operator: As name suggest it will reverse order of elements of entities.

Here is the examples of operators where i have taken simple string array to demonstrate that.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] a = { "a", "b", "c", "d" };


Console.WriteLine("Take Example");
var TkResult = a.Take(2);
foreach (string s in TkResult)
{
Console.WriteLine(s);
}

Console.WriteLine("Skip Example");
var SkResult = a.Skip(2);
foreach (string s in SkResult)
{
Console.WriteLine(s);
}

Console.WriteLine("Reverse Example");
var RvResult = a.Reverse();
foreach (string s in RvResult)
{
Console.WriteLine(s);
}

}
}
}
Here is the output as expected.LinqOperators

hope this will help you..

Technorati Tags: ,,,
Shout it
kick it on DotNetKicks.com
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews