User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 423,887 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,268 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 37566 | Replies: 2
Reply
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
Colleague
tgreer tgreer is offline Offline
Made Her Cry

ArrayList to multi-dimensional string array

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

counter = 0;
workOperations = new String [OPERATIONS.Count,2];
foreach ( System.Array o in OPERATIONS)
{
  workOperations[counter,0] = (string) o.GetValue(0,0);
  workOperations[counter,1] = (string) o.GetValue(0,1);
  counter++;
}
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: ArrayList to multi-dimensional string array

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

Re: ArrayList to multi-dimensional string array

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 4:50 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC