ArrayList from something other than primitives

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 164
Reputation: Ravenous Wolf is an unknown quantity at this point 
Solved Threads: 1
Ravenous Wolf Ravenous Wolf is offline Offline
Junior Poster

ArrayList from something other than primitives

 
0
  #1
Oct 16th, 2007
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
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you would be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "IPSE", "MIS", "OO", "BPRE".... by Edsger W. Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 2
Reputation: purunep is an unknown quantity at this point 
Solved Threads: 1
purunep purunep is offline Offline
Newbie Poster

Re: ArrayList from something other than primitives

 
0
  #2
Oct 16th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 20
Reputation: tostrinj is an unknown quantity at this point 
Solved Threads: 1
tostrinj's Avatar
tostrinj tostrinj is offline Offline
Newbie Poster

Re: ArrayList from something other than primitives

 
0
  #3
Oct 26th, 2007
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
  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:

  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
===========================
can you repeat the part of the stuff where you said all about the things?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC