ArrayList to multi-dimensional string array

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

ArrayList to multi-dimensional string array

 
0
  #1
Nov 11th, 2005
Consider the following code snippet:

  1. counter = 0;
  2. workOperations = new String [OPERATIONS.Count,2];
  3. foreach ( System.Array o in OPERATIONS)
  4. {
  5. workOperations[counter,0] = (string) o.GetValue(0,0);
  6. workOperations[counter,1] = (string) o.GetValue(0,1);
  7. counter++;
  8. }
  9. ps.Operations = workOperations;

There has got to be a better way to do this! The issue is, the ps.Operations property requries a 2-dimensional string array. (It's a list of operations to peform on a PostScript file, along with the parameters needed for each operation.)

I build that array dynamically, which means creating an ArrayList, which is "OPERATIONS" in the code. The challenge is to get the members of the ArrayList into a suitable string array. The above code is my solution.

There should be a way to do this without resorting to a loop. Just a couple of lines of code with some judicious casting, but I couldn't make anything work.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: ArrayList to multi-dimensional string array

 
0
  #2
Nov 11th, 2005
you should beable to use Array.Copy();
or since your using an arraylist do OPERATIONS.CopyTo();
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: ArrayList to multi-dimensional string array

 
0
  #3
Nov 11th, 2005
I think I tried that, but can't remember. I'll re-investigate. I think one of the issues is that each element of the ArrayList contains a 2-element array...
Reply With Quote Quick reply to this message  
Reply

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




Views: 53915 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC