Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
We have a class:
class Node
        private string gid;
        private string name;

public Node(string gimid, string ptyname)  // constructor
     gid = gimid;
     name = ptyname;

        public string gmid          // property
            get { return gid; }
            set { gid = value; }

        public string pname         // property
            get { return name; }
            set { name = value; }


And an ArrayList that will be holding above table’s structure to store records as follows:
ArrayList mapList = new new ArrayList(); 
string FirstElementID = ds.Tables[0].Rows[0]["Pty_id"].ToString();                          string FirstElementName = ds.Tables[0].Rows[0]["Pty_Name"].ToString();    
Node FirstNode = new Node(FirstElementID, FirstElementName);    

Now the question is how to access elements from this ArrayList?
Updated 5-Jun-11 15:26pm
Wonde Tadesse 5-Jun-11 16:06pm    
Which part is multidimensional ArrayList ? I can only see a single dimensional ArrayList.
Sergey Alexandrovich Kryukov 5-Jun-11 21:28pm    
Imaginary :-)
Wonde Tadesse 5-Jun-11 23:16pm    
I don't get it.
Sergey Alexandrovich Kryukov 5-Jun-11 23:33pm    
I mean you were perfectly right, nothing multidimensional, my note was sarcastic, you could pay attention for the smile.
By the way, to me all dimensions of all structures are guess what? They are all zero-dimensional. It depends on the definition of dimension.
Wonde Tadesse 5-Jun-11 23:41pm    
I get it.

You can rewrite it to

List<Node> mapList = new List<Node>()

foreach (DataRow row in ds.Tables[0].Rows)
  mapList.Add(new Node(row["Pty_id"].ToString(), row["Pty_Name"].ToString()));

And when you are done adding elements to the List. You can access, add, insert and modify the List as needed.

But it has nothing to do with a multidimensional array.
Share this answer
Sergey Alexandrovich Kryukov 5-Jun-11 21:28pm    
My 5.
Kim Togo 6-Jun-11 2:44am    
Thanks SA
I suggest you replace ArrayList with its generic counterpart List<T> where T is the type of elements in the list. In your code that would be Node. Please read about it here:[^].
That way when you access an element from that list the type will already be known and you can access all of Node's members directly without using a cast operation.

Share this answer
Espen Harlinn 5-Jun-11 6:12am    
Good point, my 5
Manfred Rudolf Bihy 5-Jun-11 7:54am    
Thank you!
Kim Togo 5-Jun-11 8:36am    
Good point, my 5. Replacing ArrayList with List<T> is much better.
Sergey Alexandrovich Kryukov 5-Jun-11 21:27pm    
Sure, my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900