Skip to main content
gamedev.net
🔒 Locked

C# dumb question

Started by dhartles Jan 21, 2005 at 9:24 AM 2 replies 400+ views
Original Post
dhartles
dhartles
OK, Need to do something here I haven't done before, and need some pointers. how do I declare a string value as a type integer, and have it visible globally? Lets say I have two or more classes. On class instatntiates one of the others, and calls one of its methods. That method requires a parameter. Instead of using a string as the param like ("Dave"), I would rather "Dave" be of an int type so that it is strongly typed. Do I need to declare some kind of a public sturct or enum to hold these values? I may not have the terminology right on some of this so please be kind. Thanks, Dave
paulecoyote
paulecoyote
Well it sounds like you want an enumeration.

But... just because something is keyed by a string doesn't mean it's not strongly typed.

See equally you could be talking about key & value pairs - so something like a Hash map / table would be what you are talking about.

Perhaps if you redesribed exactly what your goal was rather then in these rather general terms it would be easier to point you in the right direction.

Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
dhartles
dhartles
When I was developing in NeverWinter Nights Aurora Toolset, they had value types like LIGHT_YELLOW_20 that were passed as parameter into functions as a type integer. I'm trying to duplicate that functionality, such that when I type that value into a class method's parameter listing it is strongly typed and available in VS's Intellisense.

Thanks,
Dave
Monder
Monder
An enumeration is definetely what you want then. AFAIK there is no implict conversion between an enumation and an integral type in C# however you can do it explicitly (i.e. by casting). However you shouldn't really have to do this, your function can just take the enumeration type as a parameter instead of an int.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.