CSharp examples for System:Array Element
Initialize array With function
using System;/*from w w w .j av a2 s . c o m*/ public class Main{ public static T[] InitializeWith<T>(this T[] a, Func<int, T> fn) { for (var i = 0; i < a.Length; i++) { a[i] = fn(i); } return a; } public static T[] InitializeWith<T>(this T[] a, Func<T> fn) { for (var i = 0; i < a.Length; i++) { a[i] = fn(); } return a; } }