Generate array from function - CSharp System

CSharp examples for System:Array Element

Description

Generate array from function

Demo Code


using System;// www  .  jav  a 2  s  .c o m

public class Main{
        public static T[] Generate<T>(int count, Func<int, T> elementGenerator)
        {
            var table = new T[count];
            for (int i = 0; i < count; i++)
            {
                table[i] = elementGenerator(i);
            }
            return table;
        }
}

Related Tutorials