HighTechTalks DotNet Forums  

like enum, but for strings

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss like enum, but for strings in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
yanir
 
Posts: n/a

Default like enum, but for strings - 11-03-2003 , 08:14 AM






Hi
I have a function that get a string, but only of a few
specific values should be valid(e.g. the string can be
only one of the follows: "foo", "moo", "booboo") like an
enumarator that limits the integer range.

Is there any common technique to force, the developer who
call my function, to assign only those values, at compile
time and not at run time?(I know I can switch case
according to an enum but I rather to avoid it).

Thanks, Yanir

Reply With Quote
  #2  
Old   
Ron
 
Posts: n/a

Default Re: like enum, but for strings - 11-09-2003 , 01:12 PM






You can have the method that recieves the string parameter recieve the enum,
and that function can use the enum.ToString() to parse the argument as a
string:

public void Check( MyEnum x )
{
string s = x.ToString();
...
}

public void Submit()
{
Check( MyEnum.BooBoo );
}

Ron

"yanir" <yanir_r (AT) hotmail (DOT) com> wrote

Quote:
Hi
I have a function that get a string, but only of a few
specific values should be valid(e.g. the string can be
only one of the follows: "foo", "moo", "booboo") like an
enumarator that limits the integer range.

Is there any common technique to force, the developer who
call my function, to assign only those values, at compile
time and not at run time?(I know I can switch case
according to an enum but I rather to avoid it).

Thanks, Yanir



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.