对象数组是否可枚举?
在代码中查找注释
Public Class AddressCollection
Inherits System.Collections.ObjectModel.Collection(Of AddressType)
Public Sub New()
End Sub
Public Sub New(ByVal ParamArray addressTypeArray() As AddressType)
For Each currentAddress As AddressType In Me
If currentAddress IsNot Nothing Then '<<<<--NEVER HITS THIS LINE
Me.Add(currentAddress)
End If
Next
For i As Integer = 0 To addressTypeArray.Count - 1
Dim currentAddress As AddressType = addressTypeArray(i) '<<< BUT IT DOES HIT THIS LINE
If currentAddress IsNot Nothing Then
Me.Add(currentAddress)
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
我想你想要:
For Each currentAddress As AddressType In addressTypeArray
Run Code Online (Sandbox Code Playgroud)
..匹配相当于:
For i As Integer = 0 To addressTypeArray.Count - 1
Run Code Online (Sandbox Code Playgroud)