CSharp - SkipWhile operator with element index

Introduction

In the code above we skips input elements until the length is no longer greater than four characters or until the tenth element is reached.

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program/*from   w  ww  .  j a  v a 2  s.co  m*/
{
    static void Main(string[] args)
    {
        string[] codeNames = { "Python", "Java", "Javascript", "Bash", "C++", "Oracle" };

        IEnumerable<string> items = codeNames
          .SkipWhile((s, i) => s.Length > 4 && i < 10);

        foreach (string item in items)
            Console.WriteLine(item);
    }
}

Result

Related Topic