ArrayList and System.Array ?

  • Thread starter Thread starter ORC
  • Start date Start date
O

ORC

Hi,

How to create an ArrayList from a System.Array or inserting the System.Array
into the ArrayList ?

Thanks
Ole
 
Ole,

You can pass the array into the constructor of the ArrayList. It takes
an ICollection, which all arrays implement.

If you have a need to add an existing array to an array list, then you
can call the AddRange method, and pass the array through that.

Hope this helps.
 
Array implements IList and ICollection. Take a look at the constructors for
ArrayList.

Or you could use AddRange with a blank list.
 
ORC said:
How to create an ArrayList from a System.Array

As others have said, the constructor which takes an ICollection.
or inserting the System.Array into the ArrayList ?

I haven't seen any answers addressing this - use AddRange(ICollection).
 
Thank you all for your great help!

The AddRange perfectly fits my needs, but leads me to another question: is
it possible to add a part of a SystemArray to the ArrayList e.g. from index
0 to index n ?

Thanks
Ole
 
Ole,

No, it is not. The simplest way to do this would be to copy the
elements you want to add out to another array, then call AddRange, passing
that in.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
ORC said:
Thank you all for your great help!

The AddRange perfectly fits my needs, but leads me to another question: is
it possible to add a part of a SystemArray to the ArrayList e.g. from
index
0 to index n ?

Thanks
Ole
 
OK thanks! What about using an ArrayList in a call to a native DLL instead
off using a System.Array - will that be possible and is .NET able to marshal
it automatically?

Thanks,
Ole

Nicholas Paldino said:
Ole,

No, it is not. The simplest way to do this would be to copy the
elements you want to add out to another array, then call AddRange, passing
that in.

Hope this helps.
 
I will start a new thread with my last question.


ORC said:
OK thanks! What about using an ArrayList in a call to a native DLL instead
off using a System.Array - will that be possible and is .NET able to marshal
it automatically?

Thanks,
Ole

message news:[email protected]...
Ole,

No, it is not. The simplest way to do this would be to copy the
elements you want to add out to another array, then call AddRange, passing
that in.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
ORC said:
Thank you all for your great help!

The AddRange perfectly fits my needs, but leads me to another
question:
 
Back
Top