how do you use the skip while and take while methods in C# code example
Example 1: list.SkipWhile in c#
int[] sequence = { 3, 3, 1, 1, 2, 3 };
var result = sequence.SkipWhile(i => i == 3);
Example 2: 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);