Skip is LINQ functionality to filter collection by omitting given number of first elements. Below is an example how to use it.
Let’s create a simple collection of strings:
1 |
var animals = new List<string>() { "dog", "cat", "lion", "duck", "fish" }; |
Now call the Skip function with parameter 2:
1 |
var filteredAnimals = animals.Skip(2); |
Print the filtered collection to screen using foreach loop:
1 2 |
foreach (var animal in filteredAnimals) Console.WriteLine(animal); |
Result:
1 2 3 |
lion duck fish |
As we can see first two items (dog and cat) are skipped. Please notice the original collection remains unchanged.
Let’s print it to the console:
1 2 |
foreach (var animal in animals) Console.WriteLine(animal); |
Result:
1 2 3 4 5 |
dog cat lion duck fish |