Time for action – skipping save looping

Here is the first problem:

Say we have a List of names, and we want to create another List leaving the first few names:

  1. Copy the following code snippet as a query to LINQPad:
    string[] names = { "Sam", "Samuel", "Samu", "Remo", "Arnold", "Terry" };
    var skippedList = names.Skip(3);//Leaving the first 3.
    foreach (var v in skippedList)
      Console.WriteLine(v);
  2. Run the query. You will see the following output:
    Time for action – skipping save looping

What just happened?

Skip() creates an IEnumerable<T> instance that will have only the chosen few elements. In this case, we wanted to skip the first three elements. If you want to conditionally skip elements, ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.