Hi Y'all,
I have following array: double[] data1 = new double[400];
Now i want to loop through this to create a certain amount of arrays like this:
double[] data1 = new double[400];
double[] data2 = new double[400];
double[] data3 = new double[400];
I hope someone can help me out!
Thanks
double[] data1 =newdouble[400];ArrayList list =newArrayList();
//Add 100 doubles to an array list
for (int i = 0; i < 100; i++)
{
list.Add(newdouble[400]);
}
//Loop through doubles within the array list
foreach (object oDoublein list)
{
myDouble = (double)oDouble;
}
Your explanation isnt to clear! Let me know if this is what you mean!,
Good luck
Hey David,
Thanks for your reply but i need something different. I want to create for instance 10 arrays. SO loop from 0 to 9 and create name1, name2, name3...
Hope you're still there!
THanks
Hi,
You can use generic lists, ArrayList or even multi dimension arrays.
The following code uses generic list:
//Declare your list of double arrays System.Collections.Generic.List<double[]> list =new System.Collections.Generic.List<double[]>();//Add 10 new arrays to your list each of which has the capacity of 400 double value.for (int i = 0; i < 10; i++) { list.Add(new double[400]); }//if you want to access the element 300 of your 4th array: list[3][299] = 123.123;I hope this was helpful.Hey eyad!
Thanks for your reply. I'll try with multi dimension arrays.
How should i alter this line with multi dimension arrays, i mean the brackets: Lets say i want to insert the second array
layer.setXData(tijdserie);
SETXDATA always expects a DOUBLE[] so not a DOUBLE[,]
What now? :s
Hey,
Use this code (C#) for multidimensional arrays:
//multiDA is an array of ten elements, each element is an array of 400 double elementdouble[,] multiDA =new double[10,400];//Note: all 400 * 10 values of the are automatically initialized to 0 //if you want to access the 301'st element of the 4'th array multiDA[5, 300] = 233.123;
Cheers!
Hey Eyad,
Thanks, i understand your code but i can't use it. My method needs DOUBLE[]
I need code to generate 10 arrays with following names: NAME1, NAME2, NAME3, NAME4, ...
This doesn't seem to work??
for (int i=0; i<10;i++)
{
string part1fromname = "NAME" + i;
part1fromname[i] .....
}
publicvoid test()
{
Hashtable ht =newHashtable();
double[] data1 =newdouble[400];
for (int i = 0; i < 9; i++)
{
ht.Add("name" + i,newdouble[400]);
}
foreach (ListItem itemin ht)
{
double[] myDouble = (double)item.Value;
string name = (string)item.Text;
}
}
You could try that! Its getting late so please excuse errors! It shows the principle at least!
Good luck
0 comments:
Post a Comment