RE: passing enum value as an argument



That is exactly the point. I encourage Enums. Going back to the question, the
user is trying to use them without fully qualifying them which in turn
results in "defeat of the purpose" like I mentioned before.
--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray


"Jon Skeet [C# MVP]" wrote:

> Madestro <me_no_like_spam_juanDOTromero@bowneDOTcom> wrote:
> > The value of an Enum option evaluates to a constant, so technically, I COULD
> > pass a value from another Enum, so long as Option Strict is OFF and even if
> > it was on, I could cast it to the Enum.
>
> Yes, if you want to get around the type safety, you can. I don't see
> how that makes it less valuable to have enums which can be safely
> passed around if you *don't* deliberately break things, nor would
> inferring the type from the method parameter break that type safety.
>
> > The only useful things in my opinion about Enums is that they they
> > help you code fast (intellisense), you dont have to remember what
> > each value represents and it provides a range of acceptable values. I
> > don't really see any type safety benefits.
>
> Try getting the values of FileAccess, FileMode, FileShare etc the wrong
> way round on a call to the FileStream constructor. The compiler tells
> you - so long as you haven't *deliberately* started casting from one
> enum type to another via their underlying type. If you do that, you're
> clearly asking for trouble (just like if you turn option strict off) -
> but I rather like the fact that I get an error when I've *mistakenly*
> got the parameters the wrong way round.
>
> > Anyways, If the language allowed you to reference it directly, then you
> > would have ambiguity problems with variables declared in the same scope and
> > therefore WOULD defeat the purpose of having an Enum in the first place.
>
> You would only have ambiguity problems if you'd got another
> member/variable/whatever with the same name. At that point, the
> compiler could force you do disambiguate. What's the problem?
>
> (Quoting what the language specification says *now* doesn't stop the
> language changing - C# is doing exactly that when it comes to
> delegates, where the delegate type is inferred in v2.0 despite it not
> being inferred in the currently released version.)
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
>
.



Relevant Pages

  • Am I the only one who would love these extentions? - Python 3.0 proposals (long)
    ... I would like to propose some extentions to the language, ... for-as loop, until loop, unconditional loop, one line if-else, etc. ... Hex strings. ... Enum type. ...
    (comp.lang.python)
  • Re: Use enum to declare errno values
    ... C enum is not much useful in practices. ... You words on language and preprocessor doesn't make any sense. ... Without this `feature', what would a C preprocessor do? ... You've castrated cpp. ...
    (Linux-Kernel)
  • Re: passing enum value as an argument
    ... | Like I said before, ultimately, the enum evaluates to a constant, so there ... I normally use Option Strict On to ensure type safety, ... | It may not be the case in the language you are using, ... | TakeSecondEnum--> FAILS ...
    (microsoft.public.dotnet.general)
  • RE: passing enum value as an argument
    ... I could cast it to the Enum. ... clearly asking for trouble (just like if you turn option strict off) - ... > Anyways, If the language allowed you to reference it directly, then you ... You would only have ambiguity problems if you'd got another ...
    (microsoft.public.dotnet.general)
  • Problem using enum as web method parameter
    ... I am trying to localize some of the web methods in my web service so ... I've created an enum in my web service of the allowed languages: ... The first parameter in my new web methods is of the type "language". ... I'd like to be able to default the language to english if no ...
    (microsoft.public.dotnet.framework.aspnet.webservices)