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. Arraylists, Collections & Dictionaries...

Arraylists, Collections & Dictionaries...

Scheduled Pinned Locked Moved C#
questionswiftdata-structureshelpannouncement
4 Posts 2 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 Offline
    R Offline
    raysot777
    wrote on last edited by
    #1

    I need help... Here's my situation: I have an array as: string[] Array_A; byte[] Array_B; The data inside the array looks like so: Array_A: Array_B: 0x5628, 0 0x0818, 1 0x56EE, 0 0x56EE, 0 Now.. I want to add the DISTINCT values of Array_A to an 'Array_List', or collection, or dictionary :-) This new 'List' will look like so: COL_A COL_B 0x5628, 0 0x0818, 1 0x56EE, 0 ... note that the values in the B column do not matter at this point. They will be updated by another process, which leads me to my next situation. I need to update the B column by referencing the values in the A column. void UpdateArrayList(string strCheckThis, byte bData) { if(strCheckthis == Col_A) COL_ B = bData } That code is really bad in that I have no idea to know what row I am actually updating, but it gives you the basic idea of what I need to accomplish. So that's it in a nutshell.. I need to Add, Update and Remove rows in this arraylist (or Collection, or Dictionary =) The last question is: Which object fits this method best? ANY help anyone can offer will be met with swift and decisive praise and adoration... Thank you in advance Ray

    G 1 Reply Last reply
    0
    • R raysot777

      I need help... Here's my situation: I have an array as: string[] Array_A; byte[] Array_B; The data inside the array looks like so: Array_A: Array_B: 0x5628, 0 0x0818, 1 0x56EE, 0 0x56EE, 0 Now.. I want to add the DISTINCT values of Array_A to an 'Array_List', or collection, or dictionary :-) This new 'List' will look like so: COL_A COL_B 0x5628, 0 0x0818, 1 0x56EE, 0 ... note that the values in the B column do not matter at this point. They will be updated by another process, which leads me to my next situation. I need to update the B column by referencing the values in the A column. void UpdateArrayList(string strCheckThis, byte bData) { if(strCheckthis == Col_A) COL_ B = bData } That code is really bad in that I have no idea to know what row I am actually updating, but it gives you the basic idea of what I need to accomplish. So that's it in a nutshell.. I need to Add, Update and Remove rows in this arraylist (or Collection, or Dictionary =) The last question is: Which object fits this method best? ANY help anyone can offer will be met with swift and decisive praise and adoration... Thank you in advance Ray

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

      Use a hash table. Use the Add method to add the values, with the string as key, and the byte as value. Use the ContainsKey method first to check if it already exists in the table, so you don't add duplicates. To retrieve the values, use the Item method. --- b { font-weight: normal; }

      R 1 Reply Last reply
      0
      • G Guffa

        Use a hash table. Use the Add method to add the values, with the string as key, and the byte as value. Use the ContainsKey method first to check if it already exists in the table, so you don't add duplicates. To retrieve the values, use the Item method. --- b { font-weight: normal; }

        R Offline
        R Offline
        raysot777
        wrote on last edited by
        #3

        Ok.. so far so good! Here's what I have: Hashtable table = new Hashtable(); //-- Simple enough! Here's the data: table.Add("0x5628","0x5628, 0, 0"); table.Add("0x0818","0x0818, 1, 0"); table.Add("0x56ED","0x56ED, 4, 0"); Now, I want to enumerate through each element, and "Do stuff" with it... I thought this might work: foreach ( object item in table) { MessageBox.Show((string)item.ToString()); //-- Do other stuff } ...alas, though... it only displays a message as to what the object is, not what it contains. Ideally, I want to return a string from each element: "0x5628, 0, 0" From here I can parse it to my heart's desire... I just can't seem to get to the data portion. Any ideas?

        G 1 Reply Last reply
        0
        • R raysot777

          Ok.. so far so good! Here's what I have: Hashtable table = new Hashtable(); //-- Simple enough! Here's the data: table.Add("0x5628","0x5628, 0, 0"); table.Add("0x0818","0x0818, 1, 0"); table.Add("0x56ED","0x56ED, 4, 0"); Now, I want to enumerate through each element, and "Do stuff" with it... I thought this might work: foreach ( object item in table) { MessageBox.Show((string)item.ToString()); //-- Do other stuff } ...alas, though... it only displays a message as to what the object is, not what it contains. Ideally, I want to return a string from each element: "0x5628, 0, 0" From here I can parse it to my heart's desire... I just can't seem to get to the data portion. Any ideas?

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

          You are calling the ToString() method on the object before you typecast it. That will use the Object.ToString() method that just returns the name of the class. You have to typecast the object before you call any methods on it: ((string)item).ToString() The call to ToString is of course completely superflous on a string object. Just remove it: (string)item --- b { font-weight: normal; }

          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