Converting from ArrayList to non System.Type array

J

Jack Addington

I have a method that takes an array of nodes (UltraNode[]) as a parameter.

I've got an arrayList of objects that I am trying to convert to UltraNodes
and pass to the method but I cannot seem to get the syntax right.

I thought I was able to go ArrayList.ToArray(typeof(UltraNode)) and be done
with it.

I then decided to just iterate through the ArrayList and build an array but
I am having trouble there too.

Essentially I have the following (in pseudo code)

some method
{
ArrayList nodes = new ArrayList(3)

nodes.Add(new UltraNode(...));
nodes.Add(new UltraNode(...));
nodes.Add(new UltraNode(...));
}

Pass nodes around and eventually end up at a method to AddNodes( ArrayList
nodes )
{
Tree.AddRange( nodes.ToArray() );
}

I'm sure the answer is simple and elequant but I'm getting stuck.

thx

jack
 
J

Jon Shemitz

Jack said:
I have a method that takes an array of nodes (UltraNode[]) as a parameter.

I've got an arrayList of objects that I am trying to convert to UltraNodes
and pass to the method but I cannot seem to get the syntax right.

I thought I was able to go ArrayList.ToArray(typeof(UltraNode)) and be done
with it.

Close. You want

(UltraNode[]) ArrayList.ToArray(typeof(UltraNode))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top