Web
Analytics
LINQ SkipWhile() with example | Angular | ASP.NET Tutorials

For Consultation : +91 9887575540

Stay Connected :

Like TakeWhile, the SkipWhile query operator uses a predicate to evaluate each element in the input sequence. SkipWhile will ignore items in the input sequence until the supplied predicate returns false.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LINQExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Ingredient[] ingredients = 
            {
                new Ingredient {    Name = "Sugar", Calories = 500 },
                new Ingredient { Name = "Egg", Calories = 100 }, 
                new Ingredient { Name = "Milk", Calories = 150 }, 
                new Ingredient { Name = "Flour", Calories = 50 }, 
                new Ingredient { Name = "Butter", Calories = 200 } }; 
            IEnumerable query = ingredients.SkipWhile(x => x.Name != "Milk");
            foreach (var ingredient in query) 
            { 
                Console.WriteLine(ingredient.Name); 
            }
            Console.ReadLine();
        }
    }
    public class Ingredient
    {
        public string Name;
        public int Calories;
    }


}

Output

SkipWhile_demo_LINQ_yogeshdotnet

Download Source Code