tags:

views:

39

answers:

2
 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

the error is Name of field or property being initialized in an object initializer must start with '.'.

A: 

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.

Jon Skeet
im still getting error end of statement expected
@vj4u: Are you using VB10?
Jon Skeet
A: 

Try like this:

Dim list2 As List(Of String) = New List(Of String) _
        (New String() {"Bat", "ball", "Cricket"})
Darin Dimitrov