c# - Iterating the assignment of a variable's name -


so i've wondered..

say want 10 threads called t1 t2 t3 etc... don't want write

thread t1 = new thread(run); thread t2 = new thread(run); thread t3 = new thread(run); ... 

rather this: (pseudo-code)

for(int = 0; <= 10; i++){     thread t + = new thread(run); } 

is there way this?

thanks in advance.

edit: okay, wanted do:

    static void main(string[] args)     {         int n = 0;         program p = new program();         list<thread> threads = new list<thread>();          for(int = 0; <= 10; i++)         {             threads.add(new thread(p.run));         }          foreach(thread t in threads)         {             n++;             t.name = "thread " + n;             t.isbackground = true;             t.start();         }          console.readkey(false);     } 

thanks all!

no, that's not possible. why not this?

for(int = 0; <= 10; i++){     new thread(run); } 

if want keep references each thread, can store them in list.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -