Skip in LINQ

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.

Example of Skip in LINQ

		
	 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 
"); foreach (int res_data_skip in data_skip) { Response.Write(res_data_skip+" "); } It will first arrange in ascending order and then skip 3 records as we gave 3 as input in the skip.

Output:-

		
		skip example

		Figure 1

		
		

SkipWhile in LINQ

We pass lambda expression to the skipwhile which is the condition. It will start skipping the value from the beginning till the condition will be satisfied. As it will find the record which do not match the condition it will stop skipping.

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

        var data_skip = (from res_skip in marks
                       
                         select res_skip).SkipWhile(x =>x%2!=0 );
        Response.Write("use of skip while <br/>");
        foreach (int res_data_skip in data_skip)
        {
       
            Response.Write(res_data_skip+" ");
       
        }


	
		

The output of this code is as follows:-

		
		skipwhile example

		Figure 2

		
		

As you can see that it skipped the value till it’s satisfying the condition as it encountered the value 78 which do not satisfy the condition so it stopped skipping the value and select the rest of the records.

Email Address

For any query you can send mail at info@techaltum.com
Thanks