Showing posts with label skipwhile in linq. Show all posts
Showing posts with label skipwhile in linq. Show all posts

Saturday, 29 June 2013

LINQ Hour 5-3 Skip/SkipWhile and Take/TakeWhile in LINQ

Written By:-Isha Malhotra 
Our Website:-www.techaltum.com
Skip/SkipWhile and Take/TakeWhile
Skip

Skip in LINQ is used to skip values from the beginning. We pass a numeric value to skip which represent that how many values we need to skip.

For example

Skip with array

int[] marks = new int[] { 23, 45, 78, 90, 56, 89, 10, 32 };

        var data_skip = (from res_skip in marks
                         orderby res_skip
                         select res_skip).Skip(3);
        Response.Write("Result using skip and skip count is 3 <br/>");
        foreach (int res_data_skip in data_skip)
        {
       
            Response.Write(res_data_skip+" ");
       
        }
Output



Figure 1

It simple arrange in ascending order and then skip 3 records as we gave 3 as input in the skip.