Hello All:
I am writing a function which accepts an ArrayList as its parameter and
converts the contents of the ArrayList into an XmlNodeList. The ArrayList
will contain one of several different structures. For example, the
structures could be either a Customer structure (which contains a customer id
and name) or an Address structure (which contains an address type and street
number, city, etc). The XmlNodeList is uded to populate a DropDownList where
the id or address type are the ListItem's value and other information is the
ListItem's text.
I want the function to determine which structure is in the ArrayList
(Customer or Address) and cast the ArrayList entry appropriately. I can code
everything except the how to determine which structure is in the ArrayList.
For example:
Public Function Foo(AL as ArrayList) as XmlNodeList
Dim e as System.Collecti ons.iEnumerator = AL.GetEnumerato r
Do While e.MoveNext
' Determine which structure is contained in e.Current
' Perform other tasks with the e.Current entry of the ArrayList
Loop
'return some XmlNodeList
End Function
Does anyone know how to do this?
TIA,
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation 1 1736
You could do something like:
For each O as object in AL
if typeof O is CUSTOMER then ' Process as customer
elseif typeof O is ADDRESS then ' process as address
elseif etc...
end if
Next
Or you could create an interface that all your items share, and you could
cast all the items in the arraylist to that interface and treat them
identically.
----
700cb Development, Inc. http://www.700cb.net
..NET utilities, developer tools,
and enterprise solutions
=?Utf-8?B?Sm9l?= <jo******@donot spam.yahoo.com> wrote in
news:C1******** *************** ***********@mic rosoft.com: Hello All:
I am writing a function which accepts an ArrayList as its parameter and converts the contents of the ArrayList into an XmlNodeList. The ArrayList will contain one of several different structures. For example, the structures could be either a Customer structure (which contains a customer id and name) or an Address structure (which contains an address type and street number, city, etc). The XmlNodeList is uded to populate a DropDownList where the id or address type are the ListItem's value and other information is the ListItem's text.
I want the function to determine which structure is in the ArrayList (Customer or Address) and cast the ArrayList entry appropriately. I can code everything except the how to determine which structure is in the ArrayList.
For example:
Public Function Foo(AL as ArrayList) as XmlNodeList Dim e as System.Collecti ons.iEnumerator = AL.GetEnumerato r Do While e.MoveNext ' Determine which structure is contained in e.Current ' Perform other tasks with the e.Current entry of the ArrayList Loop 'return some XmlNodeList End Function
Does anyone know how to do this?
TIA,
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tweak |
last post by:
I'm struggling with the concept of typecasting when
setting up a TCP client.
Here's a code snip (modified from W. Richard Stevens Unix Programming
book) to demonstrate where I am struggling:
int sockfd;
struct sockaddr_in servaddr;
bzero(&servaddr, sizeof(servaddr));
|
by: Rustam Asgarov |
last post by:
Hi.
I have ArrayList that contains structures...
I need to iterate through all structures in this array and update one of
members in this structures...
The first thing that comes to mind is just use foreach, store struct in
temp variable , update it , then write it back to array to the same
position.
Is there more efficient way?
Thanks..
|
by: MattC |
last post by:
Hi,
How can do runtime casting?
MyCollection derives from ArrayList
I will store lost of different objects that all derive from the same parent
class. I then want to be able to pass in the object type and collection type
I have a number of classes that derive from ArrayList and have if pick out
on ly those i asked for.
|
by: JohnR |
last post by:
From reading the documentation, this should be a relatively easy thing. I
have an arraylist of custom class instances which I want to search with
an"indexof" where I'm passing an instance if the class where only the
"searched" property has a value. I expected to get the index into the
arraylist where I could then get the entire class instance. However, the
'indexof' is never calling my overloaded, overrides Equals method. Here is
the...
|
by: Maileen |
last post by:
Hi,
I would like to have something like an array (something like a
collection) in order to store the following things :
company name1, new1, old1, in1, out1
company name2, new2, old2, in2, out2
....
but i should be able to dynamically redimension it.
| |
by: Sam |
last post by:
Hi All
I'm planing to write an application which allows users dynamically add
their points (say you can add upto 30,000) and then draw xy graph. Should I
use an array for my coordinate point storage and dynamically resize it when
there is a new point or should I use ArrayList? Is speed noticable between
the two?
Regards,
|
by: mosscliffe |
last post by:
Newbie struggling with VB.NET
I wish to create an arraylist of structures. I am very new to this
coding syntax, so bear with my poor syntax - please
struct mystruct
Fld1 as short
Fld2 as integer
Fld3 as string
Fld4 as short
|
by: Christopher H |
last post by:
I've been reading about how C# passes ArrayLists as reference and Structs as
value, but I still can't get my program to work like I want it to.
Simple example:
code:------------------------------------------------------------------------------
class Program
{
static public ArrayList MyArrayList = new ArrayList();
|
by: Schkhan |
last post by:
Hi,
I am sturggling with a peace of code mainly its about casting a pointer to one type of structure to a pointer to another type of structure.
the confusion begins with the following line...(modified to highlight the actual prob)
#define TEST_MACRO(first) ((struct second *) &first)
/*here it would return a pointer to second, but the question is why it uses
Here in this example "first" and "second" are two different structures*/
|
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...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |