typecast array of object to bindinglist of object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have a Web Service that returns a bindinglist of objects. However, on the
client side it comes across as an array. Is there a way in VB.Net to
typecast the array back to a bindinglist?

TIA!
 
Hello,
I have a Web Service that returns a bindinglist of objects. However, on
the client side it comes across as an array. Is there a way in VB.Net to
typecast the array back to a bindinglist?

Note: I don't really "speak" VB, so I relied on Reflector for a bit of
translation. I hope the code is correct.

You can't typecast that array. Luckily it's very easy to create a
BindingList(Of T) from it - the following code is an example:

Dim ints As Integer() = New Integer() { 10, 20, 30 }
Dim list As New BindingList(Of Integer)(ints)

There's an important detail to understand about this. The good thing is
that the BindingList(Of T) uses the List(Of T) that you're passing in (the
array) directly, so there's no duplicating of data that could create
unwanted overhead. But there's a bad side to this as well, and it has
exactly the same reason: if you were to change an entry in the original
array after creating the BindingList(Of T) instance from it, the content
of the list would change together with the content of the array.

Hope this helps!


Oliver Sturm
 
Back
Top