473,378 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Convert Array to Generic List

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
2 15800
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
4
by: Tamir Khason | last post by:
How can I convert (elegant way) Collection to Array without looping and new instances. E.G: I want to add elements of one menu to other, so secondMenu.MenuItems.AddRange(firstMenu.MenuItems);...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
14
by: Web learner | last post by:
In the following code, I want ArrayList object x to be of type double. How can I do that? --Thanks SqlConnection objConnection = new SqlConnection("server=(local)\\SQLEXPRESS;...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
4
by: Sharon | last post by:
hello, I wanted to populate an array with the data from sql table, but not sure how to go about it. This is the array iam using at present, but i dont want to provide the values. Instead i...
6
by: Phillip.Ross.Taylor | last post by:
When I designed my application I created an object called "Orderable" which exposes a public property "sequence". Then a few objects inherit from this. I'll just call them ObjectX for the sake...
2
by: CodeMonkey775 | last post by:
I'm having problems passing a variable to a method which is executed and compiled using CodeDom. The situation is I have a List<CellData> with cells, each containing a formula (like Excel). I am...
2
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty well, but I am having trouble with generic lists,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.