Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Call Method Multuple Times

Call Method Multuple Times

Scheduled Pinned Locked Moved C#
helptutorial
13 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R RadioButton

    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

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #4

    He could also use the reverse-singleton pattern?

    I are troll :)

    J 1 Reply Last reply
    0
    • L Lost User

      He could also use the reverse-singleton pattern?

      I are troll :)

      J Offline
      J Offline
      Jon Rista
      wrote on last edited by
      #5

      :laugh:

      1 Reply Last reply
      0
      • R RadioButton

        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

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #6

        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

        D J L B 5 Replies Last reply
        0
        • D Dan Neely

          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

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #7

          I see everyone's using goto after yesterday's discussion! :laugh:

          int control = 5;
          while (control > 0)
          {
          MyMethodCall();
          control--;
          }
          //do something else

          Dave
          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)

          1 Reply Last reply
          0
          • D Dan Neely

            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

            J Offline
            J Offline
            Jon Rista
            wrote on last edited by
            #8

            :omg: That is such a bad use of goto... :wtf:

            for (int i=0; i<6; i++)
            MyMethodCall();

            1 Reply Last reply
            0
            • D Dan Neely

              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

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #9

              Let's hope count is positive now. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Love, happiness and fewer bugs for 2009!


              1 Reply Last reply
              0
              • D Dan Neely

                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

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #10

                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!


                D 1 Reply Last reply
                0
                • L Luc Pattyn

                  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!


                  D Offline
                  D Offline
                  Dan Neely
                  wrote on last edited by
                  #11

                  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

                  L 1 Reply Last reply
                  0
                  • D Dan Neely

                    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

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #12

                    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!


                    1 Reply Last reply
                    0
                    • D Dan Neely

                      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

                      B Offline
                      B Offline
                      Ben Fair
                      wrote on last edited by
                      #13

                      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 and Int32.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 the Whiskey label... Last, you could spice it up with if(!(control != 0)), that would make it really nice!

                      Keep It Simple Stupid! (KISS)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups