SkipWhile/TakeWhile Example in C# LINQ

var query9 = CustomerList.Select((cust, index) => new { cust, index })
                         // .OrderBy(c => c.cust.Country)
                         .SkipWhile(c => c.cust.Country != "USA")
                         .TakeWhile(c => c.cust.Country == "USA")
                         .Select(c => new { c.cust.CustomerID, c.cust.CompanyName, c.index });
 
foreach (var c in query9)
    sbResult.Append(String.Format("CustomerID = {0}, CompanyName = {1}, index = {2}\r\n",
                               c.CustomerID, c.CompanyName, c.index));

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.