Dimensions Of Jagged IEnumerable - CSharp System.Collections

CSharp examples for System.Collections:IEnumerable

Description

Dimensions Of Jagged IEnumerable

Demo Code


using System.Runtime.InteropServices;
using System.Reflection;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;//from  w w w.j  av a2s .c o  m

public class Main{
        private static int[] DimensionsOfJaggedIEnumerable(IEnumerable<object> enumerable)
        {
            int rank = 0;
            IEnumerable<object> parent = enumerable;
            List<int> dimensionList = new List<int>();
            while (parent != null)
            {
                rank++;
                int count = parent.FastCount();
                dimensionList.Add(count);
                parent = count == 0 ? null : parent.First() as IEnumerable<object>;
            }
            return dimensionList.ToArray();
        }
}

Related Tutorials