Public Function Cricket() As List(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
错误是在对象初始化程序中初始化的字段或属性的名称必须以“。”开头。
答案 0 :(得分:0)
我认为你想要From
而不是With
。
Dim list2 As New List(Of String)() From { _
"Bat", _
"ball", _
...
}
With
用于对象初始值设定项; From
用于集合初始值设定项。
答案 1 :(得分:0)
试试这样:
Dim list2 As List(Of String) = New List(Of String) _
(New String() {"Bat", "ball", "Cricket"})