Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET ArrayList to List(Of T) typed copy/conversion

I have a 3rd party method that returns an old-style ArrayList, and I want to convert it into a typed ArrayList(Of MyType).

Dim udc As ArrayList = ThirdPartyClass.GetValues()
Dim udcT AS List(Of MyType) = ??

I have made a simple loop, but there must be a better way:

Dim udcT As New List(Of MyType)
While udc.GetEnumerator.MoveNext
    Dim e As MyType = DirectCast(udc.GetEnumerator.Current, MyType)
    udcT.Add(e)
End While
like image 728
vulkanino Avatar asked Aug 24 '10 11:08

vulkanino


1 Answers

Dim StronglyTypedList = OriginalArrayList.Cast(Of MyType)().ToList()
' requires `Imports System.Linq`
like image 109
mmx Avatar answered Nov 11 '22 12:11

mmx