473,800 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Array of Objects to Generics List?

For example, I have the following:

Dim MyObjectArray() as Object = External.Functi on()

Is it possible to convert MyObjectArray into a Generics Collection.List ?

Thanks.

Jul 16 '06 #1
1 11188
Spam,
Have you tried:

| Dim MyObjectArray() as Object = External.Functi on()
Dim theList As New List(Of Object)(MyObjec tArray)

If you really want theList to be List(Of Whatever) then you need to start
with an array of Whatever or convert the MyObjectArray to an array of
Whatever first.
| Dim MyObjectArray() as Object = External.Functi on()
Dim MyWhateverArray () As Whatever
MyWhateverArray = Array.ConvertAl l(Of Object,
Whatever)(MyObj ectArray, AddressOf Converter)
Dim theList As New List(Of Whatever)(MyWha teverArray)

Private Function Converter(ByVal value As Object) As Whatever
Return CType(value, Whatever)
End Function

Alternatively you could use a For Each to read the MyObjectArray adding the
items to theList.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Spam Catcher" <sp**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
| For example, I have the following:
|
| Dim MyObjectArray() as Object = External.Functi on()
|
| Is it possible to convert MyObjectArray into a Generics Collection.List ?
|
| Thanks.
|
Jul 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6319
by: Harry Overs | last post by:
My program needs to take a pointer to BYTE array (unsigned char*) and convert it into a STL list so that each BYTE in the array has its own element in the list, i.e. if the array has hundred bytes then the list needs to have a hundred entries, at present when I try to do this each element in my list points to the entire BYTE array, when what I really need is copies of each single BYTE in its own part of the list. I have used code similar...
2
2041
by: Raphael Iloh | last post by:
Hi all, I'm having problems comparing array objects. Take a look at this: int array1 = new int{1}; int array2 = new int{1}; Console.Writeln(array1.Equals(array2)); One would expect the above expression to return true as both arrays are identically the same but it keeps returning false. Any info on how to solve this problem will be appreciated.
1
1818
by: Michael Rockwell | last post by:
I am using a generics List<MyStructure> object of a structure of information I need in my application. Initially I created a predicate to retrieve the correct struct of data, but I am finding that this approach is very CPU intensive ~15% for just the look up. I did a test where I created a list that contained just the index values I needed so that I could use a BinarySearch to give me an index value that I could use to pull the item out...
10
12233
by: Steve | last post by:
this code: private Array m_arrays = new Array; results in an array of 3 null Array objects. What am I missing?
2
35820
by: Joe | last post by:
Hi I have a Generics List in a PropertyGrid I am able to Serialize it to XML but when I try to deserialize back to the class of the PropertyGrid The Constructor doesn't seem to fire to reload the saved settings Can anyone see something that I have missed ?
5
2329
by: zefciu | last post by:
Hi! I want to embed a function in my python application, that creates a two-dimensional array of integers and passes it as a list (preferably a list of lists, but that is not necessary, as the python function knows the dimensions of this array). As I read the reference, I see, that I must first initialize a list object and then item-by-item put the values to the list. Is there any faster way to do it? And is it worth to implement? ...
4
6503
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be retrieved using list/menu box. When i check only a single checkbox to insert the checked category ,selecting that category through list box gives out the entire data of the user corresponding to that category. However when i check multiple checkboxes and...
7
6357
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
Say I have a class that has a generics List as follows: public List<MyClassmyClassList = new List<MyClass>(); and I want to create another class which tries to add an element of MyClass to that list, but it is not explicitly creating an instance of MyClass, but instead using the Activator to create an instance based on it's type name. How can I accomplish this in C# using reflection?
2
16008
by: Chris Kennedy | last post by:
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...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.