Converting from ArrayList to non System.Type array

  • Thread starter Thread starter Jack Addington
  • Start date Start date
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
 
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))
 
Back
Top