Reputation: 1219
Is there a way how can I declare variables in a for loop and using the "int i" as a part of the variable name?
I'm trying to set some adjustments of my excel chart in a for loop and assigning different colours needs different series for each line :|.
I want something like this:
for(int i=0; i < myMaximum; i++ )
{
Excel.Series series_i+1 = (Excel.Series)mychart.SeriesCollection(i+1);
series_i+1.Border.Color = mycolors[i];
}
Is something like this possible? I need to do it in for loop because the number of series depends on the number of myMaximum.
Upvotes: 1
Views: 152
Reputation: 15158
In this loop:
for(int i=0; i < myMaximum; i++ )
{
Excel.Series series_i+1 = (Excel.Series)mychart.SeriesCollection(i+1);
series_i+1.Border.Color = mycolors[i];
}
series_i+1
will live for the scope of the loop only, not sure why you need a different name if you stay in the same scope, it doesn't make much sense to have a different variable name that never exits the loop.
This would work just the same way:
for(int i=0; i < myMaximum; i++ )
{
mychart.SeriesCollection(i+1).Border.Color = mycolors[i];
}
I appologize if I completely missed the point, I've re-read the question a bunch of times.
Upvotes: 2