1

First of all, this question is not a duplicate of this one or this one. I am not looking for answers taking the form of

Some_struct[] struct_array = new[]{
    Some_struct(parameters),
    Some_struct(parameters),
    ...
}

with Some_struct has a parameterized constructor.

The array to be created is large in size. Is there a way that one can initialize the array all at once without iterating over its indexes and explicitly initializing each data member?

John Z. Li
  • 1,893
  • 2
  • 12
  • 19

1 Answers1

2

If you need to pass parameters you need a constructor. Otherwise you can simply use:

var array = new Some_struct[1000000];

Since structs are value types, they are all initialized with the default values.

Some_struct s = array[4711]; // never null
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939