I am aware that in C# const can only be initialized at compile time. Which is related to what I am trying to do.
My objective is to write a constant array of constant objects in C#. How can I do that?
In order to explain my self, allow me to insert some code in C++ (I wrote some code some time ago) that explains what I am trying to do.
(In C++)
struct FD{
string name;
double CE[2];
};
const FD models[2]={
{"one",{2.0,1.0}},
{"two",{3.0,4.0}}
};
Seems very simple, right? How can I do something like this in C#?
EDIT: (Attempted answer)
I found that you can do something like this in C#
struct FD
{
public string name;
public double[] CE;
}
static readonly FD[] models= new[]
{
new FD(){name="one" , CE= new double[]{1.0,2.0 } },
new FD(){name="two", CE= new double[]{3.0,4.0}}
};
I wonder if this could be a good way to achieve my objective?