944,198 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 4352
  • C# RSS
Oct 16th, 2007
0

ArrayList from something other than primitives

Expand Post »
Hi. I need some help with arraylists. i can do a basic arraylist which uses integers and strings and so on. but what i need is an arraylist composed of something else.

best would be an arraylist composed of arraylists. like a multi dimensional array. is it possible to create multi dimensional arrays and if it is then how does one use it? if you guys can just give me basic guide lines for creating, adding, reading and removing

otherwise can i use the array list with an array of strings. or with a set of class objects. if i use it with an array of strings then what do i use as in the cast operation? can i just use the string array int the form (string[])? and if i use class objects which i create then i suppose that i can use the class in the cast
Similar Threads
Reputation Points: 33
Solved Threads: 1
Junior Poster
Ravenous Wolf is offline Offline
164 posts
since Aug 2007
Oct 16th, 2007
0

Re: ArrayList from something other than primitives

hi! I think you need to use generic arraylist.
which helps you to add only string in arraylist or class in arraylist.
hope that it works for you.

regards,
purunep
Reputation Points: 10
Solved Threads: 1
Newbie Poster
purunep is offline Offline
2 posts
since Oct 2007
Oct 26th, 2007
0

Re: ArrayList from something other than primitives

ok, here is an example: data is stored in xml and represents the table, need array list of array lists of xml nodes to do some intelligent sorting
C# Syntax (Toggle Plain Text)
  1.  
  2. ArrayList _arrMaster = new ArrayList
  3.  
  4. foreach(XmlNode rNode in XmlTable)
  5. {
  6. if(IsStartOfGroup(rNode)) //if we need to start up a group I need a new array list
  7. {
  8. ArrayList _arrSub = new ArrayList();
  9. _arrSub.Add(rNode);
  10. /*add few more xml nodes and then move to the next group */
  11. _arrMaster.Add(_arrSub);
  12. }
  13. }
this is very simplified, but at the end you get:

ArrayList that holds multiple array lists that holds multiple xml nodes that should be grouped together for some reason.

to work this:

C# Syntax (Toggle Plain Text)
  1. private void ReIndexMaster(ref ArrayList master)
  2. {
  3. int iRowCount = 1;
  4. int iCellCount = 1;
  5. foreach(ArrayList tmp in master)
  6. {
  7. foreach(XmlNode rNode in tmp)
  8. {
  9. rNode.Attributes["index"].Value = iRowCount.ToString();
  10. rNode.Attributes["o_index"].Value = iRowCount.ToString();
  11. iRowCount += 1;
  12. iCellCount = 1;
  13.  
  14. foreach(XmlNode cNode in rNode)
  15. {
  16. cNode.Attributes["index"].Value = iCellCount.ToString();
  17. iCellCount += 1;
  18. }
  19. }
  20. }
  21. }
So the answer - multi dimensional arrays are good for you and are possible. Remember ArrayList holds object and everything is an object (even collections like arraylsits)so there is no limit. I have simplified this example but using casting you can get to any element within a top or bottom level of your arraylist.

Paul
Reputation Points: 12
Solved Threads: 1
Newbie Poster
tostrinj is offline Offline
20 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Displaying an XML table
Next Thread in C# Forum Timeline: Problem with Form and Combox selections





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC