我有一个返回旧式ArrayList的第三方方法,我想将其转换为类型化的ArrayList(Of MyType).
Dim udc As ArrayList = ThirdPartyClass.GetValues() Dim udcT AS List(Of MyType) = ??
我做了一个简单的循环,但必须有一个更好的方法:
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
Dim StronglyTypedList = OriginalArrayList.Cast(Of MyType)().ToList() ' requires `Imports System.Linq`