I have a class that inherits NameObjectCollectionBase called Products. In
the class' constructor, I add items using BaseAdd(key,value), where key is a
string representation of an id and value an instance of another class called
Product. For example:
Me.BaseAdd(Id,New Product(Id, Name, Price))
In another class, I would like to Enumerate the contents of the Products
class like so:
Dim product As Product
For Each product In Products
Response.Write(product .Id & ":" & product .Name & ":" & product .Price
& "<BR>")
Next
Unfortunately, when the code hits the line For Each product In Products, I
get an error that reads:
Specified cast is not valid.
It appears that the product is actually a string, not the object. What am I
doing incorrectly?
Thanks,
Craig Buchanan 2 1687
For Each product In Products.Product
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... I have a class that inherits NameObjectCollectionBase called Products. In the class' constructor, I add items using BaseAdd(key,value), where key is
a string representation of an id and value an instance of another class
called Product. For example:
Me.BaseAdd(Id,New Product(Id, Name, Price))
In another class, I would like to Enumerate the contents of the Products class like so: Dim product As Product
For Each product In Products
Response.Write(product .Id & ":" & product .Name & ":" & product
..Price & "<BR>")
Next
Unfortunately, when the code hits the line For Each product In Products, I get an error that reads:
Specified cast is not valid.
It appears that the product is actually a string, not the object. What am
I doing incorrectly?
Thanks,
Craig Buchanan
Mike-
Thanks for the reply.
I get an error proclaiming that 'Product' isn't a member of 'Products'.
Obviously, as I haven't added a 'Product' property.
What am I missing? Perhaps an Item property?
Thanks,
Craig
"Mike Lincoln" <ml*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... For Each product In Products.Product
"Craig Buchanan" <so*****@somewhere.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... I have a class that inherits NameObjectCollectionBase called Products.
In the class' constructor, I add items using BaseAdd(key,value), where key
is a string representation of an id and value an instance of another class called Product. For example:
Me.BaseAdd(Id,New Product(Id, Name, Price))
In another class, I would like to Enumerate the contents of the Products class like so: Dim product As Product
For Each product In Products
Response.Write(product .Id & ":" & product .Name & ":" & product .Price & "<BR>")
Next
Unfortunately, when the code hits the line For Each product In Products,
I get an error that reads:
Specified cast is not valid.
It appears that the product is actually a string, not the object. What
am I doing incorrectly?
Thanks,
Craig Buchanan
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Billy Jacobs |
last post by:
I am getting an error saying:
Public Method BaseGet not found on
Type 'clsRunCollection'.
The error occurs on the call to Public Property Run. If I
change the parameter to an integer it works...
|
by: Rein Petersen |
last post by:
Hi Everyone!
I hope someone may have experience serializing a NameObjectCollectionBase
(System.Collections.Specialized) and can advise me as to why I receive this
error (below) when I try to...
|
by: William Stacey [MVP] |
last post by:
What is the deal with NameObjectCollectionBase? It allows duplication keys
to be added to the hashtable
using System;
using System.Collections;
using System.Collections.Specialized;
...
|
by: Mark Overstreet |
last post by:
Hi,
I have several custom collections that inherit from
System.Collections.Specialized.NameObjectCollectionBase and I want to
serialize and deserialize with the XMLSerializer object. This works...
|
by: Mark Overstreet |
last post by:
I am writing custom collections for my business objects but I need support
for the foreach construct. I also need key support so I am inheriting from
NameObjectCollectionBase. I need to support...
|
by: V. |
last post by:
Hi,
I need to sort the object
System.Collections.Specialized.NameObjectCollectionBase based on one
property of the special object. Is there an easy way to do this?
Thanks
Vicky
|
by: Sam Marrocco |
last post by:
I've created a collection class that inherits the
NameObjectCollectionBase. I'd like to add a few functions, such as being
able to insert a new item at an indexed or keyed location in the...
|
by: Sam Marrocco |
last post by:
I've constructed a class that inherits the NameObjectCollectionBase
class. All works well, but I'd like to shadow the GetEnumerator method
so that it returns an actual value *instead of a...
|
by: Sam Marrocco |
last post by:
I've created a collection class that inherits NameObjectCollectionBase
(call it MyCollection). MyCollection is declared as serializable, and
serializes fine. A cursory glance into the serialized...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 ...
| |