public class Sample
{
static int count = 0;
public int abc;
public Sample()
{
abc = ++Sample.count;
}
}
I want to
Here is another one-liner that doesn't require any extension method:
Sample[] array = Enumerable.Range(0, 100).Select(i => new Sample()).ToArray();
Another nice option is Scott's suggestion to Jon's answer:
public static T[] Populate(this T[] array)
where T : new()
{
for (int i = 0; i < array.Length; i++)
array[i] = new T();
return array;
}
So you can do:
Sample[] array = new Sample[100].Populate();