This is a C# newbie question.
Consider the following array declaration and initialization:
// This declare the array and initialize it with the default values
double[] MyArray = new double[3];
Somewhere in my code, I initialize the array as follows:
MyArray[0] = 1d;
MyArray[1] = 2d;
MyArray[2] = 3d;
I know that I can assign multiple constants at once to the array at the time of declaration as follows:
double[] MyArray = new double[3] {1d, 2d, 3d};
How to do such an initialization but not at the time of declaration in C#?
In VB.NET, it can be done as follow:
Dim MyArray(3) As Double
...
MyArray = {1#, 2#, 3#} ' Assign multiple values at once
Update
The reason why I want to separate between declaration and initialization is that the initialization will be inside a loop.
List<double>will be a better option.