In a nutshell SkipWhile is the counterpart of TakeWhile. Enumerable.SkipWhile bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements. This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. To show a sample usage, I provided a sample code that skip numbers from a list that are less than 10 until it encounters a number that is greater or equal to 10.
static void Main(string[] args)
{
int[] intnum = { 1, 3, 5, 7, 9, 11, 8, 9, 1, 2 };
var lessthan10 = intnum.SkipWhile(x => x < 10);
Console.WriteLine("Numbers that are less than 10.");
foreach (var x in lessthan10)
{
Console.WriteLine(x);
}
Console.ReadKey();
}
The LINQ code above will produce the following result:
For more LINQ coding tips & tricks, subscribe now.
Thursday, June 25, 2009




0 comments:
Post a Comment