Link to home
Start Free TrialLog in
Avatar of SSschultz
SSschultz

asked on

C# using string as part of int

Hi,
Can you help with the following:

I need to have a int that has a string as part of the name.
Example:
int XYZ100;
and want to assign a value to int XYZ100 by a string so that when
the string = XYZ, it will know to use int XYZ100.

This is for streaming data so it needs to be fast and not looking for simple if statement,
I'm currenly using If statements but need to expand to more than 200 different int and think there is faster way then if statements (hardcoded).

I'm not sure if Dictionary is the fastest?
I would like someone to show how to do the above by using just string and the int.
Reflection has been suggested but as a slower solution.
Any suggestions and examples greatly appreciated.
thanks
newbie
ASKER CERTIFIED SOLUTION
Avatar of w00te
w00te
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SSschultz
SSschultz

ASKER

w00te,

I'm using public static variables/int to use in other classes forms etc.
I guess I can use public static dictionary and do lookup outside collection classes and
would work same as public static var?
Do you think public static Dictionary would be as fast as public static int?
Got your point that dictionary is probably fastest within the collection class.

The reason for having the stringname in the integer name is because the value collection from the streaming collection is applicable to specific characters, so in order to keep track of it I was/am currently using int with name of the string including to separate each string char because there are certain caluclations on int for each different stringname.
Make sense.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HiI SSschultz i suggested you to user  IDictionary in your previous question (not closed btw) so i am supprised why are you oppening new one :)

If your set of XYZnn is determinstic you can fill your dictionary with all posible combinations so you only need to set value when data arrive.  This way you will get some on speed.

Hi qsiric,
Yes, I opened a second question because I wanted to see if I asked the question a different way if some different ideas would be suggested. I'll be closing both questions within the day.
It appears that the public static dictionary is working across classes.