Welcome to Vishwa's blog - Technology, Spirituality and More...

Convert Array to Generic List

You can happily use .NET Generics in WCF Services. But when you will get the proxy of the respective service, these generics will get converted into Array, even you are using .NET to develop the client application. So now the question is how I should get back from Array to Generic List again.


Simple Example

  Dim someArray() As Integer = {1, 2, 3, 4, 5}

        Dim genericList As New List(Of Integer)



Web Service Example

  Dim resp As New MyLookupService.GetCountriesResponse

        Dim reqs As New MyLookupService.GetCountriesRequest

        Dim listData As New List(Of MyLookupService.CountryData)

        Dim arrData As Array


        reqs.LoginInfo = loginReq

        resp = srvObj.GetCountries(reqs)

        arrData = resp.CountriesInfo



        Me.gvwCountry.DataSource = listData



Alternate Option

        When you Add Service Reference, click on "Advanced..." button on bottom left and Choose Collection Type from Dropdown as "System.Collections.Generic.List" and you are all set. No need to use array.


Comments (2) -

  • Stop Dreaming Start Action

    8/30/2009 1:16:36 AM | Reply

    i feel very lucky can find this page..
    finally i find something that i want to know..
    thank you for this usefull informations..

  • Susan

    9/7/2010 8:40:33 AM | Reply

    Found your blog whilst searching with google and they have certainly delivered this time. The information contained within this post, is not only very informative but gives the reader exactly what they are looking for.
    Brilliant article, thank you for sharing!