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. Passing in an array

Passing in an array

Scheduled Pinned Locked Moved C#
csharpvisual-studiomcpdata-structures
9 Posts 4 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.
  • M Offline
    M Offline
    Muntyness
    wrote on last edited by
    #1

    Is there any way to do something like this: StartScreen.mCP.talkTime("#FM", "01", {newINIs, items}); Which is to say passing in an array without actually making the array, or do I need to do it like this: object[] o = new object[] {newINIs, items}; StartScreen.mCP.talkTime("#FM", "01", o); Something like the first way would be better more useful, but Visual Studio doesn't like it, so... - Munty

    L D 2 Replies Last reply
    0
    • M Muntyness

      Is there any way to do something like this: StartScreen.mCP.talkTime("#FM", "01", {newINIs, items}); Which is to say passing in an array without actually making the array, or do I need to do it like this: object[] o = new object[] {newINIs, items}; StartScreen.mCP.talkTime("#FM", "01", o); Something like the first way would be better more useful, but Visual Studio doesn't like it, so... - Munty

      L Offline
      L Offline
      LiquidE_SA
      wrote on last edited by
      #2

      Hi. Try something like this StartScreen.mCP.talkTime("#FM", "01", new object[]{newINIs, items}); I don't know if it'll work, but try it. One never know. ASBESTOS-Greetings

      M 1 Reply Last reply
      0
      • L LiquidE_SA

        Hi. Try something like this StartScreen.mCP.talkTime("#FM", "01", new object[]{newINIs, items}); I don't know if it'll work, but try it. One never know. ASBESTOS-Greetings

        M Offline
        M Offline
        Muntyness
        wrote on last edited by
        #3

        That worked perfectly. Thanks - Munty

        L G 2 Replies Last reply
        0
        • M Muntyness

          That worked perfectly. Thanks - Munty

          L Offline
          L Offline
          LiquidE_SA
          wrote on last edited by
          #4

          No problem ASBESTOS-greeting LiquidE

          1 Reply Last reply
          0
          • M Muntyness

            That worked perfectly. Thanks - Munty

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            You are still creating the array, though...

            --- b { font-weight: normal; }

            M 1 Reply Last reply
            0
            • G Guffa

              You are still creating the array, though...

              --- b { font-weight: normal; }

              M Offline
              M Offline
              Muntyness
              wrote on last edited by
              #6

              Yeah, but I'm now creating a temporary array inside the method call, which is how I wanted it. Plus if I call half a dozen methods, I dont have to remember what names I've used for the arrays previously. (The contents of the array assumed to be different for every call because it's something the user can modify whenever he wants to) - Munty

              G 1 Reply Last reply
              0
              • M Muntyness

                Yeah, but I'm now creating a temporary array inside the method call, which is how I wanted it. Plus if I call half a dozen methods, I dont have to remember what names I've used for the arrays previously. (The contents of the array assumed to be different for every call because it's something the user can modify whenever he wants to) - Munty

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Just wanted to be clear on whether it was the actual creating of an array that was the problem or not. :)

                --- b { font-weight: normal; }

                1 Reply Last reply
                0
                • M Muntyness

                  Is there any way to do something like this: StartScreen.mCP.talkTime("#FM", "01", {newINIs, items}); Which is to say passing in an array without actually making the array, or do I need to do it like this: object[] o = new object[] {newINIs, items}; StartScreen.mCP.talkTime("#FM", "01", o); Something like the first way would be better more useful, but Visual Studio doesn't like it, so... - Munty

                  D Offline
                  D Offline
                  dbetting
                  wrote on last edited by
                  #8

                  The easiest way to do it is to create a new collections class. The collection class can be of whatever you need. Now your parameter is the class object. You populate it with what you need in the parent method, pass in the populated class to the called method.

                  M 1 Reply Last reply
                  0
                  • D dbetting

                    The easiest way to do it is to create a new collections class. The collection class can be of whatever you need. Now your parameter is the class object. You populate it with what you need in the parent method, pass in the populated class to the called method.

                    M Offline
                    M Offline
                    Muntyness
                    wrote on last edited by
                    #9

                    Nah, because I'd still need to adjust the collections class before I used the method, because the contents of the array changes every time the method is used. The array can be null; a string; a string and a boolean; an array, 2 booleans and a string; etc, and it's contents will be different every time it's called. All in all, much easier to use the (new Object{}) code to pass stuff into the method. - Munty

                    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