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. Array List

Array List

Scheduled Pinned Locked Moved C#
helpdata-structuresquestion
2 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.
  • U Offline
    U Offline
    User 956892
    wrote on last edited by
    #1

    Hi Everybody, I wrote a class like this public class Node { private int data; private string key; #region Constructors public Node(string key, int data) { this.key = key; this.data = data; } #endregion #region Public Properties public int Value { get { return data; } set { data = value; } } public string Key { get { return key; } set { key = value; } } #endregion } public class test { public static void Main() { ArrayList a = new ArrayList(); Node n = new Node("ab", 1); a.Add(n); PrintValues(a); } public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "\t{0}", myEnumerator.Current.ToString()); Console.WriteLine(); } } My problem is How do I get and set values for each node in this Array List and How do I print out to the screen. Thanks for your help and time. Raj

    S 1 Reply Last reply
    0
    • U User 956892

      Hi Everybody, I wrote a class like this public class Node { private int data; private string key; #region Constructors public Node(string key, int data) { this.key = key; this.data = data; } #endregion #region Public Properties public int Value { get { return data; } set { data = value; } } public string Key { get { return key; } set { key = value; } } #endregion } public class test { public static void Main() { ArrayList a = new ArrayList(); Node n = new Node("ab", 1); a.Add(n); PrintValues(a); } public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "\t{0}", myEnumerator.Current.ToString()); Console.WriteLine(); } } My problem is How do I get and set values for each node in this Array List and How do I print out to the screen. Thanks for your help and time. Raj

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      You have to cast the elements of your ArrayList. public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) { Console.Write( "\t{0}", ((Node) myEnumerator.Current).Key.ToString()); Console.WriteLine(); } }

      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