I have been playing around linq and I have found great method call SkipWhile method. SkipWhile methods skips particular element which matches condition in predicate this can be use full in condition where we need to skip elements on particular condition.
So let’s take some example. I have written following console application code.
In the above code I have created a array of string called names and I want to skip names starts with letter “j” with help of ‘SkipWhile’. I am printing each item via for each loop. Following is the output as expected.
That’s it.Hope you liked it. Stay tuned for more..Till then happy programming.
So let’s take some example. I have written following console application code.
using System; using System.Collections.Generic; using System.Linq; namespace Linq { class Program { static void Main(string[] args) { string[] names = { "Jalpesh", "Jayesh", "Tushar", "Tejas", "Sanjay", "Nijesh" }; foreach(var name in names.SkipWhile(s=>s.ToLower().StartsWith("j"))) { Console.WriteLine(name); } } } }
In the above code I have created a array of string called names and I want to skip names starts with letter “j” with help of ‘SkipWhile’. I am printing each item via for each loop. Following is the output as expected.
That’s it.Hope you liked it. Stay tuned for more..Till then happy programming.
Sorry if I'm being dense; couldn't you also use a Where clause for this?
ReplyDeleteblaster151 - There is major difference between skipwhile and where. Where filters the things. While skipwhile skip the elements until condition is true . I will post a blog on that
ReplyDelete