473,804 Members | 3,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to CAST string into object (hashtable)

Hi everybody,
I'm a new in C# and have a problem

I need to create dynamically the name of object
let's say "obj1", "obj2" etc. They're hashtables (Action Script
objects)

I'm doing like
String tempStr = "obj" + i.ToString();
then
ASObject tempStr = new ASObject();
this gives an problem, beacuse temStr is already defined as a string
and recasting in this context is not possible.

Java and VB can easy resolve it, not speaking about scripting
languages were exists special functions like Eval(), but C# has some
different way.
If somebody knows something about it?
Thanks a lot!
Nov 16 '05 #1
2 8941
Peter <pk******@hotma il.com> wrote:
I'm a new in C# and have a problem

I need to create dynamically the name of object
Objects don't have names. Variables have names, but objects don't
(generally).
let's say "obj1", "obj2" etc. They're hashtables (Action Script
objects)

I'm doing like
String tempStr = "obj" + i.ToString();
then
ASObject tempStr = new ASObject();
this gives an problem, beacuse temStr is already defined as a string
and recasting in this context is not possible.

Java and VB can easy resolve it, not speaking about scripting
languages were exists special functions like Eval(), but C# has some
different way.
I presume by "Java" here you actually mean Javascript.
If somebody knows something about it?


Either use an array of objects, or use a hashtable mapping from name to
object.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Your description is quite vague on what you actually want to do.

For example, to solve the only problem you actually mention in your
message, all you need do is simply change

String tempStr = "obj" + i.ToString();
ASObject tempStr = new ASObject();

to

String tempStr = "obj" + i.ToString();
ASObject tempASO = new ASObject();

so, clearly that's not the real problem. Tell us a bit more clearly what
you want to use this for.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
"Peter" <pk******@hotma il.com> wrote in message
news:ea******** *************** ***@posting.goo gle.com...
Hi everybody,
I'm a new in C# and have a problem

I need to create dynamically the name of object
let's say "obj1", "obj2" etc. They're hashtables (Action Script
objects)

I'm doing like
String tempStr = "obj" + i.ToString();
then
ASObject tempStr = new ASObject();
this gives an problem, beacuse temStr is already defined as a string
and recasting in this context is not possible.

Java and VB can easy resolve it, not speaking about scripting
languages were exists special functions like Eval(), but C# has some
different way.
If somebody knows something about it?
Thanks a lot!

Nov 16 '05 #3

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

Similar topics

4
3744
by: Clint Hill | last post by:
I am working on a project that I would like to have some extensibility for later. So with this I am using interfaces to pass objects to derived classes. However I am running into a situation where two seperate classes won't cast each other even though they implement the same interface. The classes are identical yet won't convert. Here is (briefly) what I am talking about: public interface IReturnObject { Guid ID { get; set; } string...
6
3543
by: Doug | last post by:
I have data that looks something like this when returned from a stored procedure (3 columns, X rows): Key1 Name1 Value1 Key1 Name2 Value2 Key1 Name3 Value3 Key1 Name4 Value4 Key2 Name1 Value1 Key2 Name2 Value2 Key3 Name1 Value1
2
2102
by: Nick | last post by:
Out of context and just asking but why does the following code work? Hashtable ht = new Hashtable(); ht.Add(1,1); .... .... ..... ICollection collection = ht.Values; Hashtable ht2 = (Hashtable)collection.SyncRoot;
2
1622
by: Jon | last post by:
Hello all, Can some please help with an error I'm having. I'm binding a Hashtable to a Repeater and on the ItemDataBound event i have this code: if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataRowView dataRowView = (DataRowView)e.Item.DataItem;
0
1886
by: Genival P.Carvalho | last post by:
Hello folks, First sorry my bad english. I will try to implement a IExtenderProvider + Verbs (Designer). When compile tha follow code its compile fine, but whem drag resulting componet under form i gain a error: Specified Cast Is Not Valid :( Code. #Region "NameSpaces Area"
2
5516
by: andrewcw | last post by:
Typically I get a DictionaryEntry from a foreach when walking a Hashtable. My impression is that the foreach returns one item of the hash. One of my commonly used functions received takes a DictionaryEntry as a parameter. In several instances I dont want to recreate a foreach item. but this code to create the dictionaryEntry did not work: eg: Hashtable hTableProcedureTables = new Hashtable();
10
8514
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 synced, many threads can directly
15
37600
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code Different-2 string.
8
5870
by: Ashish Khandelwal | last post by:
-----See below code, string str = "blair"; string strValue = "ABC"; string str1 = "brainlessness"; string strValue1 = "XYZ"; int hash = str.GetHashCode() ; // Returns 175803953 int hash1 = str1.GetHashCode(); // Returns 175803953 Hashtable ht = new Hashtable(); ht.Add(hash ,strValue); ht.Add(hash1,strValue1); // ****ERROR****
0
9706
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
10583
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...
1
10323
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,...
0
10082
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...
0
9160
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
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
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.