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:
- 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);
- Run the query. You will see the following output:
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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.