Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using enum as a parameter
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00971423
Message ID:
00971742
Views:
12
I didn't know you could pass other values then what is define in the enum. I guess it's a good thing... it opens up ways to build hidden features into methods, which in nice. something like this:
public void myMethod (myEnum e)
{
     switch (e)
     {
        case e.SomeValue:
           DoSometing();
           break;
        default:
           switch ( (int)e )
           {
              case 100:
                DoSomeUndocumentedFeature();
                break;
              case ....
           }
     }
}
Thanks for the info Cetin.

>Stephane,
>Correct you are, but, like Cetin said, I can cast a value to the enum and it still works even if that value casted is not contained in the enum.
>
>This works:
>test.Class1.myMethod((test.Class1.myEnum) 1);
>
>but this doesn't
>test.Class1.myMethod(1);
>
>So it appears that I still have to validate the parameter passed. Shoot I was hoping that I didn't have to validate by passing an enum.
>
>Einar
>
>
>>I guess it will work with 0, probably because 0 is the default value for all enum types. But it will not work with any other value.
Previous
Reply
Map
View

Click here to load this message in the networking platform