loop through method

  • Thread starter Thread starter RobcPettit
  • Start date Start date
R

RobcPettit

Hi, Im not sure how to word this question, hopefully it will be understandable. I'm adding lines to a chart. No problems doing this. I have a method that assigns the line a color. To do this i use 'line ln = new line();'. Then ln.linestyle.color = color.blue; This works great. If i have say, twenty lines the i have to declare new lines, ln1....ln20. the ln1.linestyle........ln20.linestyle. Which is ok, just alot of typing. Is it possible to dothis with a loop. I've tried using a string, string test = ln + i, then test.line..... But of course I get a compile error. Im a diy csharper, so my knowledge is books and internet. So im not sure which area this comes under.
Regards Robert
 
Hi, Im not sure how to word this question, hopefully it will be
understandable. I'm adding lines to a chart. No problems doing this.
I have a method that assigns the line a color. To do this i use 'line
ln = new line();'. Then ln.linestyle.color = color.blue; This works
great. If i have say, twenty lines the i have to declare new lines,
ln1....ln20. the ln1.linestyle.......ln20.linestyle. Which is ok,
just alot of typing. Is it possible to do this with a loop. I've
tried using a string, string test = ln + i, then test.line..... But
of course I get a compile error. Im a diy csharper, so my knowledge
is books and internet. So im not sure which area this comes under.

If the number of lines are fixed during execution, then you can
use an array.

If you want the ability to change size dynamically, then go for
a List<>.

If in doubt go for List<>.

Arne

PS: Traditionally both type names and property names are capitalized - I
will recommend following the convention.
 
Thankyou both for replies. So obvious when explained. Makes the code so much more readable as well. Thankyou.
Regards Robert
 
Back
Top