Issue
Need syntax help, is there any way of calling the same method of multiple instances in one statement, like the way we assign values to multiple variables?
var t1 = new Thread(SayHello);
var t2 = new Thread(SayBye);
var t3 = new Thread(SayGoodbye);
(t1.Name, t2.Name, t3.Name) = ("Thread1", "Thread2", "Thread3");
// any way to call t1,t2, and t3's Start Method in one statement like above
t1.Start();
t2.Start();
t3.Start();
Solution
You can't call the Start() method of multiple objects in one statement as you would assign the same value to multiple variables in one statement: The Start() method is an element within each object, not the same piece of code attached to each one. The closest you're going to be able to come is in IamK's comment
(new List<Thread> { t1, t2, t3 }).ForEach(_=> _.Start());
which is a valid construct, as opposed to the merely conceptual one I thought up
(t1, t2, t3).Start();
Answered By - FKEinternet Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.