loop through method

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
 
A

Arne Vajhoej

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.
 
R

RobcPettit

Thankyou both for replies. So obvious when explained. Makes the code so much more readable as well. Thankyou.
Regards Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top