skip and take while code example
Example: list.Skip, list.SkipWhile, list.Take, list.TakeWhile in c#
IList<string> strList = new List<string>(){ "One", "Two", "Three", "Four", "Five" };
var newList = strList.Take(2);
foreach(var str in newList)
Console.WriteLine(str);
IList<string> strList = new List<string>() {
"One",
"Two",
"Three",
"Four",
"Five",
"Six" };
var resultList = strList.TakeWhile((s, i) => s.Length > i);
foreach(string str in resultList)
Console.WriteLine(str);
IList<string> strList = new List<string>(){ "One", "Two", "Three", "Four", "Five" };
var newList = strList.Skip(2);
foreach(var str in newList)
Console.WriteLine(str);
IList<string> strList = new List<string>() {
"One",
"Two",
"Three",
"Four",
"Five",
"Six" };
var resultList = strList.SkipWhile(s => s.Length < 4);
foreach(string str in resultList)
Console.WriteLine(str);