Mike
Mike

Reputation: 2376

Going through a list and adding its individual values to a statement

For each of the int's in a list (mylist) I would like the following to be executed:

e.g.

// Add series and points
ramChart.Series["RAM"].Points.AddY(mylist[0]);
ramChart.Series["RAM"].Points.AddY(mylist[1]);
ramChart.Series["RAM"].Points.AddY(mylist[2]);

and so on until there it has gone through all of the list values

Upvotes: 0

Views: 126

Answers (2)

Adrian
Adrian

Reputation: 5681

something like this:

for (i=0 .. mylist.size(){
    ramChart.Series["RAM"].Points.AddY(mylist[i]);
}

perhaps use an iterator, but I dont really know c# syntax

edit: you can speed this process up by doing list concatenation instead of adding elements one by one

Upvotes: 0

Justin Niessner
Justin Niessner

Reputation: 245399

Do you mean something as simple as:

foreach(var i in mylist)
{
    ramChart.Series["RAM"].Points.AddY(i);
}

Upvotes: 4

Related Questions