To Array by index on IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

To Array by index on IEnumerable

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*from  w w w .  ja v a2  s.com*/

public class Main{
    public static T[] ToArray<T>(IEnumerable<T> list, int index, int count)
    {
      List<T> intermediate = new List<T>(list);
      List<T> range = intermediate.GetRange(index, count);
      return range.ToArray();
    }
    public static T[] ToArray<T>(IEnumerable list)
    {
      var result = new List<T>();
      foreach (var item in list)
      {
        result.Add((T)item);
      }
      return result.ToArray();
    }
    public static T[] ToArray<T>(IEnumerable<T> list)
    {
      List<T> intermediate = new List<T>(list);
      return intermediate.ToArray();
    }
    public static IList<T> GetRange<T>(IEnumerable<T> list, int index, int count)
    {
      List<T> intermediate = new List<T>(list);
      return intermediate.GetRange(index, count);
    }
}

Related Tutorials