vb.net即将收到错误

时间:2010-06-28 11:43:17

标签: vb.net

 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

错误是在对象初始化程序中初始化的字段或属性的名称必须以“。”开头。

2 个答案:

答案 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"})