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. ArrayList Help Needed for Newbie...

ArrayList Help Needed for Newbie...

Scheduled Pinned Locked Moved C#
tutorialcsharpsysadminjsonperformance
3 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.
  • G Offline
    G Offline
    gman44
    wrote on last edited by
    #1

    I'm aware of how to use arrays similar to the following example. static void Main() { ArrayList list = new ArrayList(); list.Add(45); list.Add(87); list.Add(12); foreach(int num in list) { Console.WriteLine(num); } } However, I'm trying to capture data strings from a log server and parse them in memory rather than FileStreaming them to a log.txt file and parsing later. I can view the ArrayList activity with a listBox and it seems to me it only holds one (1) string at a time. I need a growing list in memory that I can sort and parse. Here's my failing setup so far. Help...... (C#) str = System.Text.Encoding.ASCII.GetString(data); //data is a Byte[] Al = new ArrayList(1024); Al.Add(str); foreach(string Line in Al) { listBox1.Items.Add(Line.ToString()); } // Knowledge is a one way street, Wisdom is looking both ways before crossing :)

    C L 2 Replies Last reply
    0
    • G gman44

      I'm aware of how to use arrays similar to the following example. static void Main() { ArrayList list = new ArrayList(); list.Add(45); list.Add(87); list.Add(12); foreach(int num in list) { Console.WriteLine(num); } } However, I'm trying to capture data strings from a log server and parse them in memory rather than FileStreaming them to a log.txt file and parsing later. I can view the ArrayList activity with a listBox and it seems to me it only holds one (1) string at a time. I need a growing list in memory that I can sort and parse. Here's my failing setup so far. Help...... (C#) str = System.Text.Encoding.ASCII.GetString(data); //data is a Byte[] Al = new ArrayList(1024); Al.Add(str); foreach(string Line in Al) { listBox1.Items.Add(Line.ToString()); } // Knowledge is a one way street, Wisdom is looking both ways before crossing :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You've only added one string to the arrayList, so how many were you hoping would come out ? If there is a seperator in the byte[] that denotes the position of multiple strings, then use the Split function of the string class to turn str into a String[], which you can then foreach into the listbox. Assuming your delimiter is a slash or something, otherwise you may have to parse the byte array instead. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      1 Reply Last reply
      0
      • G gman44

        I'm aware of how to use arrays similar to the following example. static void Main() { ArrayList list = new ArrayList(); list.Add(45); list.Add(87); list.Add(12); foreach(int num in list) { Console.WriteLine(num); } } However, I'm trying to capture data strings from a log server and parse them in memory rather than FileStreaming them to a log.txt file and parsing later. I can view the ArrayList activity with a listBox and it seems to me it only holds one (1) string at a time. I need a growing list in memory that I can sort and parse. Here's my failing setup so far. Help...... (C#) str = System.Text.Encoding.ASCII.GetString(data); //data is a Byte[] Al = new ArrayList(1024); Al.Add(str); foreach(string Line in Al) { listBox1.Items.Add(Line.ToString()); } // Knowledge is a one way street, Wisdom is looking both ways before crossing :)

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        just bind the arraylist's datasource and dont add/remove items to the listbox itself eg. listBox1.DataSource = Al; SHould be all you need. Look at the help too, if you want to customise the display of the listbox (something member (datamember?) property). :) top secret xacc-ide 0.0.1

        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