Convert Array of Objects to Generics List?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

For example, I have the following:

Dim MyObjectArray() as Object = External.Function()

Is it possible to convert MyObjectArray into a Generics Collection.List?

Thanks.
 
Spam,
Have you tried:

| Dim MyObjectArray() as Object = External.Function()
Dim theList As New List(Of Object)(MyObjectArray)

If you really want theList to be List(Of Whatever) then you need to start
with an array of Whatever or convert the MyObjectArray to an array of
Whatever first.


| Dim MyObjectArray() as Object = External.Function()
Dim MyWhateverArray() As Whatever
MyWhateverArray = Array.ConvertAll(Of Object,
Whatever)(MyObjectArray, AddressOf Converter)
Dim theList As New List(Of Whatever)(MyWhateverArray)

Private Function Converter(ByVal value As Object) As Whatever
Return CType(value, Whatever)
End Function

Alternatively you could use a For Each to read the MyObjectArray adding the
items to theList.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| For example, I have the following:
|
| Dim MyObjectArray() as Object = External.Function()
|
| Is it possible to convert MyObjectArray into a Generics Collection.List?
|
| Thanks.
|
 

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

Back
Top