0

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?

1
  • "explicitly each data member" missing the predicate Commented Apr 27, 2018 at 9:12

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.