vb.net im getting error
Public Function Cricket() As L开发者_如何学JAVAist(Of String)
Dim list2 As New List(Of String)() With { _
"Bat", _
"ball", _
"Cricket", _
"baseball", _
"MLB", _
"Derbyshire", _
"Durham", _
"Essex", _
"Glamorgan", _
"Gloucestershire", _
"Hampshire", _
}
'string str;
Return list2
End Function
the error is Name of field or property being initialized in an object initializer must start with '.'.
Try like this:
Dim list2 As List(Of String) = New List(Of String) _
(New String() {"Bat", "ball", "Cricket"})
I think you want From
instead of With
.
Dim list2 As New List(Of String)() From { _
"Bat", _
"ball", _
...
}
With
is used for object initializers; From
is used for collection initializers.
精彩评论