473,569 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hashtable of objects and need to convert at runtime

2 New Member
I'm stuck with a problem where I need to convert hastable contents to a object type at runtime... below is the code..


//
Portfolio pf = GlobalVariables .portfolio;
IEnumerator pfDealsEnum = pf.getPortfolio Deals().GetEnum erator();
while (pfDealsEnum.Mo veNext()){
Deal deal = (Deal)pfDealsEn um.Current;
}

I dont know why this is not converting, I used to do such things in VB.net but here in C#. this is not working.

Any help is more than welcome. Please respond asap.

Regards
Rajiv
Mar 27 '07 #1
2 1165
RedSon
5,000 Recognized Expert Expert
I'm stuck with a problem where I need to convert hastable contents to a object type at runtime... below is the code..


//
Portfolio pf = GlobalVariables .portfolio;
IEnumerator pfDealsEnum = pf.getPortfolio Deals().GetEnum erator();
while (pfDealsEnum.Mo veNext()){
Deal deal = (Deal)pfDealsEn um.Current;
}

I dont know why this is not converting, I used to do such things in VB.net but here in C#. this is not working.

Any help is more than welcome. Please respond asap.

Regards
Rajiv
Are you sue that its not Current() or some other method that will return the current value of what the enumerator is pointed to? You may want to read up on your enumerators by visiting MSDN.
Mar 27 '07 #2
rajivksh
2 New Member
Are you sue that its not Current() or some other method that will return the current value of what the enumerator is pointed to? You may want to read up on your enumerators by visiting MSDN.

Thanx for the suggestion...

the issue is that the IEnumrator shud be started with
.Values of hashtable and not on the hashtable as such. I discovered that by looking at some older coding that I had done in VB.Net

The right code will be

IEnumerator pfDealsEnum = pf.getPortfolio Deals().Values. GetEnumerator() ;
NOT

IEnumerator pfDealsEnum = pf.getPortfolio Deals().GetEnum erator();

Thanx
Mar 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3975
by: Cederstrom | last post by:
Hello group! :) I want to create a config/status object, that will contain a Hashtable. This object I would like to save through Serialization, but im having some trouble. My hashtable contain some objects, from a class I created myself. I read that I need to make my own "add" method, which I hopefully did correct. I hope someone can spot...
10
2815
by: Brian | last post by:
I'm reasonably new to C#, and using a class containing a hashtable collection to feed a treeview. My problem is that I can't pull the data from the hashtable! Here's the code I have: if (myItem.DataFields.Count != 0) foreach (string name in myItem.DataFields.Values) { treeView1.SelectedNode.Nodes.Add (name); // Error on this line }
5
2814
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object.
9
4031
by: Oberon | last post by:
My HashTable (Global.Games) is a static collection of objects of type Game. A Game object has 8 fields (exposed as properties). The key to the HashTable is also one of these fields (GameID, of type int). When I try to create a SortedList from the HashTable with the following: SortedList sortedGames = new SortedList(Global.Games); I get...
1
2329
by: oDDskOOL | last post by:
I realized today that the Hashtable.Clone only produces a shallow copy... that makes me go mad that M$ doesn't even provide a deep copy ctor for the Hashtable class ! mighty tech ducks might reply "oh but what if the types in hastable don't have copy ctors defined? that could lead to dangerous situations". well, but was it a significant...
10
348
by: SK | last post by:
Hey, i have a hashtable, where I am adding some values. Now when I iterate through them then they start in reverse order, why is that happening and how can I get rid of it? Thanks
10
2082
by: Q | last post by:
Hi, I'm using a hashtable to store away a bunch of numbers from my array: The Hashtable should look like: Key Value 1 01234 2 01235
15
3083
by: Macca | last post by:
Hi, My app needs to potentially store a large number of custom objects and be able to iterate through them quickly. I was wondering which data structure would be the most efficient to do this,a hashtable or a generic list. Is using enumerators to iterate through the data structure a good idea? I'd appreciate any suggesstions or advice,
10
8489
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new Hashtable()); 2. create ArrayList aList = ArrayList.Synchronized(new ArrayList()); 3. create a string sList = ""; For 1 and 2, since the list is...
0
7703
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...
0
7926
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. ...
0
8138
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...
1
7679
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...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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...
0
5223
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...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
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 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.