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.

C#, using GeSHi 1.0.8.6
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] a = { "a", "b", "c", "d" };
  14.            
  15.  
  16.             Console.WriteLine("Take Example");
  17.             var TkResult = a.Take(2);
  18.             foreach (string s in TkResult)
  19.             {
  20.                 Console.WriteLine(s);
  21.             }
  22.  
  23.             Console.WriteLine("Skip Example");
  24.             var SkResult = a.Skip(2);
  25.             foreach (string s in SkResult)
  26.             {
  27.                 Console.WriteLine(s);
  28.             }
  29.  
  30.             Console.WriteLine("Reverse Example");
  31.             var RvResult = a.Reverse();
  32.             foreach (string s in RvResult)
  33.             {
  34.                 Console.WriteLine(s);
  35.             }
  36.              
  37.         }
  38.     }
  39. }
Parsed in 0.020 seconds at 44.65 KB/s

Here is the output as expected.

LinqOperators

hope this will help you..

Technorati Tags: ,,,
Shout it
Published Friday, June 18, 2010 1:02 PM by Jalpesh P. Vadgama
Filed under: , , ,

Comments

# Twitter Trackbacks for Take,Skip and Reverse Operator in Linq - DotNetJaps [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 Take,Skip and Reverse Operator in Linq - DotNetJaps         [asp.net]        on Topsy.com

# Object Oriented Programing » Take,Skip and Reverse Operator in Linq

Pingback from  Object Oriented Programing » Take,Skip and Reverse Operator in Linq

Leave a Comment

(required) 
(required) 
(optional)
(required)