Rotate element from IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Rotate element from IEnumerable

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;//from ww  w .  j a v  a 2s . c  om

public class Main{
    public static IEnumerable<T> Rotate<T>(this IEnumerable<T> enumerable, int elementCount)
    {
      foreach (var element in enumerable.Skip(elementCount))
      {
        yield return element;
      }

      foreach (var element in enumerable.Take(elementCount))
      {
        yield return element;
      }
    }
}

Related Tutorials