Call Method Multuple Times
-
Hello, I would like to call a method multiple times by a count. For example: If count = 6 call method 6 times. Thank you so much for the help. RB
-
Hello, I would like to call a method multiple times by a count. For example: If count = 6 call method 6 times. Thank you so much for the help. RB
for[^] You need to read very basic c# book.
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
Hello, I would like to call a method multiple times by a count. For example: If count = 6 call method 6 times. Thank you so much for the help. RB
1.
for(int i=0; i< count; i++) myPopularMethod(withPossiblySomeArguments);
2. or create a delegate and an event; add the delegate count times to the event and call the event. :)Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Hello, I would like to call a method multiple times by a count. For example: If count = 6 call method 6 times. Thank you so much for the help. RB
-
Hello, I would like to call a method multiple times by a count. For example: If count = 6 call method 6 times. Thank you so much for the help. RB
Int control= count;
Whiskey:
if (control== 0)
goto Foxtrot;
else
goto Tango;Tango:
MyMethodCall();
control--;
goto Whiskey;FoxTrot:
//do something else
Edit: Improved code.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
modified on Thursday, January 8, 2009 3:38 PM
-
Int control= count;
Whiskey:
if (control== 0)
goto Foxtrot;
else
goto Tango;Tango:
MyMethodCall();
control--;
goto Whiskey;FoxTrot:
//do something else
Edit: Improved code.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
modified on Thursday, January 8, 2009 3:38 PM
I see everyone's using goto after yesterday's discussion! :laugh:
int control = 5;
while (control > 0)
{
MyMethodCall();
control--;
}
//do something elseDave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
Int control= count;
Whiskey:
if (control== 0)
goto Foxtrot;
else
goto Tango;Tango:
MyMethodCall();
control--;
goto Whiskey;FoxTrot:
//do something else
Edit: Improved code.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
modified on Thursday, January 8, 2009 3:38 PM
-
Int control= count;
Whiskey:
if (control== 0)
goto Foxtrot;
else
goto Tango;Tango:
MyMethodCall();
control--;
goto Whiskey;FoxTrot:
//do something else
Edit: Improved code.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
modified on Thursday, January 8, 2009 3:38 PM
Let's hope count is positive now. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Int control= count;
Whiskey:
if (control== 0)
goto Foxtrot;
else
goto Tango;Tango:
MyMethodCall();
control--;
goto Whiskey;FoxTrot:
//do something else
Edit: Improved code.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
modified on Thursday, January 8, 2009 3:38 PM
Hi, labels too deserve meaningful names, they add to the readability of the source code; so I would suggest:
uint control= count;
WhileThereMayBeMore:
if (control== 0)
goto FinallyWhenDone;
else
goto ThisIsWhereWeCallTheMethod;ThisIsWhereWeCallTheMethod:
MyMethodCall();
control--;
goto WhileThereMayBeMore;FinallyWhenDone:
//do something else
BTW: why is it all examples seem to use PascalCase labels, they are local after all? (e.g. read MSDN on the goto keyword) :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Hi, labels too deserve meaningful names, they add to the readability of the source code; so I would suggest:
uint control= count;
WhileThereMayBeMore:
if (control== 0)
goto FinallyWhenDone;
else
goto ThisIsWhereWeCallTheMethod;ThisIsWhereWeCallTheMethod:
MyMethodCall();
control--;
goto WhileThereMayBeMore;FinallyWhenDone:
//do something else
BTW: why is it all examples seem to use PascalCase labels, they are local after all? (e.g. read MSDN on the goto keyword) :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
My labels do have meaningful names when looked at collectively. Perhaps I was too subtle. :doh:
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
-
My labels do have meaningful names when looked at collectively. Perhaps I was too subtle. :doh:
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
Sure they do, however you could combine individual and collective meaning, yielding the best of both worlds. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Int control= count;
Whiskey:
if (control== 0)
goto Foxtrot;
else
goto Tango;Tango:
MyMethodCall();
control--;
goto Whiskey;FoxTrot:
//do something else
Edit: Improved code.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
modified on Thursday, January 8, 2009 3:38 PM
Hmm, I'm sure you could fit some XML in there, keep the counter in a database table, or even create a custom
CountNotYetAchieved Exception
class. I'd even settle for a string counter andInt32.Parse
it on each iteration. Come on guys, integer counters are soooo yesterday! Here's my real version:while(count-- > 0) MyMethod();
One other thing is the
else
technically is unnecessary in theWhiskey
label... Last, you could spice it up withif(!(control != 0))
, that would make it really nice!Keep It Simple Stupid! (KISS)