开发者

vb.net im getting error

开发者 https://www.devze.com 2023-01-05 10:20 出处:网络
Public Function Cricket() As L开发者_如何学JAVAist(Of String) Dim list2 As New List(Of String)() With { _
 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消