Hi mates,
How to use a string , to be a variable name, for example
suppose X="WELL"
then I want to have an array with this name -> double [] WELL = new double[10];
more specifically I want to create a set of arraies, in which the name of array is obtained by a loop:
for ( int i=0;i<20;i++)
{
string X= "WELL"+i.ToString();
double [] X = new double [10]; //???
}
Then I want to have a set of array :
double [] WELL1 =new double [10];
double [] WELL2 =new double [10];
...
double [] WELL19 = new double[10];
Thanks,
Loading
Guest UserPosted Dec 17, 2010, 12:21 PM
It isn't possible to do this in C#, but you can assign a name to each array of doubles if you store the string/array pairs in a generic dictionary as in this example:
// use a generic dictionary to hold the "WELL" names and arrays of doubles doubleHolder = new Dictionary();
Dictionary
// create the dictionary elements, based on your loop
for ( int i = 0; i < 20; i++ )
{
string x = "WELL" + i.ToString();
double[] arr = new double[ 10 ];
doubleHolder.Add( x, arr );
}
// you can then reference each array of doubles by the "WELL" name
double[] w2 = doubleHolder[ "WELL2" ];
Sam HobbsPosted Dec 17, 2010, 11:49 PM