943,990 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 70786
  • C# RSS
Nov 11th, 2005
0

ArrayList to multi-dimensional string array

Expand Post »
Consider the following code snippet:

C# Syntax (Toggle Plain Text)
  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.
Similar Threads
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Nov 11th, 2005
0

Re: ArrayList to multi-dimensional string array

you should beable to use Array.Copy();
or since your using an arraylist do OPERATIONS.CopyTo();
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Nov 11th, 2005
0

Re: ArrayList to multi-dimensional string array

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...
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

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: Array["name"] instead of Array[int]
Next Thread in C# Forum Timeline: Data stored in Records





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


Follow us on Twitter


© 2011 DaniWeb® LLC