RE: passing enum value as an argument
- From: "Madestro" <me_no_like_spam_juanDOTromero@bowneDOTcom>
- Date: Tue, 12 Jul 2005 15:30:02 -0700
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
>
.
- Follow-Ups:
- RE: passing enum value as an argument
- From: Jon Skeet [C# MVP]
- RE: passing enum value as an argument
- References:
- passing enum value as an argument
- From: Glenn Venzke
- RE: passing enum value as an argument
- From: Madestro
- RE: passing enum value as an argument
- From: Jon Skeet [C# MVP]
- RE: passing enum value as an argument
- From: Madestro
- RE: passing enum value as an argument
- From: Jon Skeet [C# MVP]
- passing enum value as an argument
- Prev by Date: RE: DataItem.Eval inside <FooterTemplate>
- Next by Date: Re: Global Assembly Cache
- Previous by thread: RE: passing enum value as an argument
- Next by thread: RE: passing enum value as an argument
- Index(es):
Relevant Pages
|