0

I try to define double arrays but their names are in a string array. Is it possible to do something like that :

string[] arrayNames = new string[] {"a", "b", "c"};

double[] arrayNames[0] ; // problem is here.I try to give names dynamically

ps: Of course this code doesn't work ;) Thanks...

dnur
  • 709
  • 3
  • 13
  • 21

4 Answers4

3

Look at the IDictionary<string, IEnumerable>

sll
  • 61,540
  • 22
  • 104
  • 156
3

Why don't you use a Dictionary?

Dictionary<string, double[]> doubleArrays = new Dictionary<string, double[]>();

doubleArrays.Add("a", new double[] { 1.0, 1.2 });
// etc.
double[] someArray = doubleArrays["a"];
Botz3000
  • 39,020
  • 8
  • 103
  • 127
0

It is not possible to have "dynamic variable names" in C# - see for example Dynamic variable in C#?.

Community
  • 1
  • 1
Jonas Heidelberg
  • 4,984
  • 1
  • 27
  • 41
0

Maybe you need the array of dynamic objects?

var array = new[] {new {Foo=1}, new {Foo=2}}; 
EgorBo
  • 6,120
  • 3
  • 35
  • 40