Groups | Blog | Home
all groups > dotnet framework > december 2006 >

dotnet framework : typecast array of object to bindinglist of object



param NO[at]SPAM community.nospam
12/20/2006 10:49:07 AM
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!

Oliver Sturm
12/21/2006 3:22:21 PM
Hello,

[quoted text, click to view]

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
--
AddThis Social Bookmark Button