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. Moving an array element to a variable.

Moving an array element to a variable.

Scheduled Pinned Locked Moved C#
data-structures
4 Posts 3 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.
  • L Offline
    L Offline
    Lecutus1
    wrote on last edited by
    #1

    Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks

    OriginalGriffO D L 3 Replies Last reply
    0
    • L Lecutus1

      Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      I tried it:

          public static string\[\] Trux\_Info = new string\[20\];
      
          public static string port\_in = "";
      
          private void button1\_Click(object sender, EventArgs e)
              {
              Trux\_Info\[0\] = "Hello";
              Trux\_Info\[1\] = "There";
              Trux\_Info\[2\] = "This";
              Trux\_Info\[3\] = "Is";
              Trux\_Info\[4\] = "A";
              Trux\_Info\[5\] = "Test";
      
              port\_in = Trux\_Info\[3\];
              MessageBox.Show(port\_in);
              }
      

      It show "Is" - which is what I would expect. So, there is something you aren't telling us. Give us a cut-down-but-still-not-working sample of the code that isn't doing it's job, and tell us what it is doing instead.

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • L Lecutus1

        Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks

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

        Griff is right. There's something you're not telling us. What IS it doing and what are you EXPECTING it to do?? We also need to see a more complete code snippet showing the offending code.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        1 Reply Last reply
        0
        • L Lecutus1

          Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks

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

          Ok It's one of those things where another of section of code was causing the problem. It had nothing to do with the array. Problem fixed array transfered properly. Say it with me now, ROOKIE!!!!!!!!!!!!!! I do appreciate the expediant answers. Consider this line/thread closed Thanks L.

          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