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/* ww  w .  j  a  va 2  s. c om*/
{
    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