By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,423 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,423 IT Pros & Developers. It's quick & easy.

Convert Array to Generic List

P: n/a
I am getting a generic list of objects from a webservice. The list is
converted to an array by this process. How do I convert the array back to a
list and is there any way of finding an object within the list via one it's
properties. I have seen it done in C# but not VB.
E.g. obj = get object from list where obj.id = 1. I could do some kind of
solution using loops but I was hoping for something a little more slick.
This is for .net 2.0 by the way. Regards, Chris.

Aug 31 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Aug 31, 8:25*pm, "Chris Kennedy" <chris.kenned...@btinternet.com>
wrote:
I am getting a generic list of objects from a webservice. The list is
converted to an array by this process. How do I convert the array back toa
list and is there any way of finding an object within the list via one it's
properties. I have seen it done in C# but not VB.
E.g. obj = get object from list where obj.id = 1. I could do some kind of
solution using loops but I was hoping for something a little more slick.
This is for .net 2.0 by the way. Regards, Chris.
Hi,
I don't know if it doesn't what you're looking for, but List type has
AddRange method to adds elements into List.
Imports System
Imports System.Collections.Generic
' Assuming you have an Integer array of IDs
Dim intArray() As Integer = {0,1,2,3....} ' goes on
Dim intList As New List(Of Integer)
intList.AddRange(intArray)

Hope this helps,

Onur Güzel
Aug 31 '08 #2

P: n/a
Chris Kennedy wrote:
I am getting a generic list of objects from a webservice. The list is
converted to an array by this process. How do I convert the array back
to a list
You just create a list and supply the array to the constructor. It will
then loop through the array and add them to the list. Example:

Dim stringList As New List(Of String)(stringArray)
and is there any way of finding an object within the list via
one it's properties. I have seen it done in C# but not VB.
E.g. obj = get object from list where obj.id = 1. I could do some kind
of solution using loops but I was hoping for something a little more
slick. This is for .net 2.0 by the way. Regards, Chris.
If you have VS2008, you can use anonymous methods in VB. If I remember
the syntax correctly:

Dim result As List(Of SomeClass) = someList.FindAll(Function(item As
SomeClass) item.id = 1)

Otherwise you have to use a named method:

Function FindId(item As SomeClass)
Return item.id = 1
End Function

Dim result As List(Of SomeClass) = someList.FindAll(AddressOf FindId)

--
Göran Andersson
_____
http://www.guffa.com
Sep 1 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.