.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Lambda Expressions Extension Method 5 - Skip()

Posted By:Jean Paul       Posted Date: May 10, 2011    Points: 200    Category: LINQ    URL: http://www.dotnetspark.com  

In this article I will show how to use Skip() method in Lambda Expressions Extension Method 5 - Skip()
 

Skip() Extension Method

The Skip() is a simple method that skips the first n elements in the enumerable.

It is similar to Take() method in the sense, Take() will return the first n elements, but Skip() will skip the first n elements. (n is the count of elements)

Parameters: Integer specifying Number of Elements to be skipped

Return Value: List of Items

Example

In the following example we are using a list of integers and the Skip() method to select the top n numbers from the list.

        private IList<int> _list = new List<int>();

 

        public InitializeList()

        {

            // Set data

            _list.Add(1);

            _list.Add(2);

            _list.Add(3);

            _list.Add(4);

            _list.Add(5);

            _list.Add(6);

        }

 

        private void SkipButton_Click(object sender, EventArgs e)

        {

            /// Skip method to get a sublist by skipping the first n elements

            var result = _list.Skip(3);

 

            foreach (int i in result)

                MessageBox.Show(i.ToString());

        }

 

 

 

Input

1

2

3

4

5

6

 

 

 

Output

4

5

6

 

Extension Method Snapshot

You can find the snapshot of the Skip() method usage as provided by Visual Studio.


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend