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. I need to create 150 variable names....need an efficient way of doing it

I need to create 150 variable names....need an efficient way of doing it

Scheduled Pinned Locked Moved C#
question
15 Posts 6 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.
  • S Sundeepan Sen

    What if its an array of objects? class[] object = new class();?

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

    sundeepan wrote:

    What if its an array of objects?

    Nothing, no problem :-)

    S 1 Reply Last reply
    0
    • M monstale

      sundeepan wrote:

      What if its an array of objects?

      Nothing, no problem :-)

      S Offline
      S Offline
      Sundeepan Sen
      wrote on last edited by
      #7

      heh, cool..so now i'm stuck at how to return all the elements of an array at the end of a method I cant do

      for(int i = 0; i < 20; i++)
      {
      return arrayOfObjects[i];
      }

      I will have unreachable code.

      M D 2 Replies Last reply
      0
      • S Sundeepan Sen

        heh, cool..so now i'm stuck at how to return all the elements of an array at the end of a method I cant do

        for(int i = 0; i < 20; i++)
        {
        return arrayOfObjects[i];
        }

        I will have unreachable code.

        M Offline
        M Offline
        monstale
        wrote on last edited by
        #8

        return will jump out of the method. ;-) What are you trying to do?

        S 1 Reply Last reply
        0
        • M monstale

          return will jump out of the method. ;-) What are you trying to do?

          S Offline
          S Offline
          Sundeepan Sen
          wrote on last edited by
          #9

          I am trying to return an array...but I cant do return objectArray; the compiler error: Error 1 Cannot implicitly convert type 'Interactive.Geo.WellLog.Track.cgStackedTrack[]' to 'Interactive.Geo.WellLog.Track.cgStackedTrack' C:\Program Files\INT\Net\3.0.3693.0\Tutorials\WellLog.NET\StackedTrackTutorial\StackedTrackTutorial.cs 177 20 StackedTrackTutorial

          M L 2 Replies Last reply
          0
          • S Sundeepan Sen

            I am trying to return an array...but I cant do return objectArray; the compiler error: Error 1 Cannot implicitly convert type 'Interactive.Geo.WellLog.Track.cgStackedTrack[]' to 'Interactive.Geo.WellLog.Track.cgStackedTrack' C:\Program Files\INT\Net\3.0.3693.0\Tutorials\WellLog.NET\StackedTrackTutorial\StackedTrackTutorial.cs 177 20 StackedTrackTutorial

            M Offline
            M Offline
            monstale
            wrote on last edited by
            #10

            Check definition of method - should return cgStackedTrack[] if you want to do this ;-)

            S 1 Reply Last reply
            0
            • S Sundeepan Sen

              I am trying to return an array...but I cant do return objectArray; the compiler error: Error 1 Cannot implicitly convert type 'Interactive.Geo.WellLog.Track.cgStackedTrack[]' to 'Interactive.Geo.WellLog.Track.cgStackedTrack' C:\Program Files\INT\Net\3.0.3693.0\Tutorials\WellLog.NET\StackedTrackTutorial\StackedTrackTutorial.cs 177 20 StackedTrackTutorial

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

              Well obviously if you first say you're going return something of type T and then decide to return a T[] instead, that wouldn't work. Can you change the method signature, or is it fixed in some way?

              1 Reply Last reply
              0
              • M monstale

                Check definition of method - should return cgStackedTrack[] if you want to do this ;-)

                S Offline
                S Offline
                Sundeepan Sen
                wrote on last edited by
                #12

                Hey thanks! I think I fixed it. Sorry for the stupid question...

                1 Reply Last reply
                0
                • S Sundeepan Sen

                  heh, cool..so now i'm stuck at how to return all the elements of an array at the end of a method I cant do

                  for(int i = 0; i < 20; i++)
                  {
                  return arrayOfObjects[i];
                  }

                  I will have unreachable code.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #13

                  Soooooo how did you think you were going to return the values of 150 different variables??

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008
                  But no longer in 2009...

                  1 Reply Last reply
                  0
                  • S Sundeepan Sen

                    I need to create 150 variable names. They must be like "varName01" , "varName01" all the way to 150. How do I do this using a for or while loop? thanks! Sundeep

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #14

                    Do you really have a valid need to do this?

                    Online only for only an hour a day. Please expect delay in response.

                    S 1 Reply Last reply
                    0
                    • D dan sh

                      Do you really have a valid need to do this?

                      Online only for only an hour a day. Please expect delay in response.

                      S Offline
                      S Offline
                      Sundeepan Sen
                      wrote on last edited by
                      #15

                      Well...yes..but I at the end I figured out that I did not need to create 150 variable names. An array worked fine. Sorry for the newbie question, I am a newbie and basically I've learned not to be afraid of asking "newbie" or stupid questions. That's the way I learn.... once again I apologize f :) r my idiocy.

                      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