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
Title:
Using enum as a parameter
Miscellaneous
Thread ID:
00971423
Message ID:
00971423
Views:
62
I tried using an enum as a parameter and it worked well but not quite like I expected.
Consider the sample code:
public enum myEnum : byte
{
  SR0 = 0xE0,
  SR1 = 0xE1,
  SR2 = 0xE2
}

public static void myMethod (myEnum paraMyEnum)
{
  MessageBox.Show(((byte) paraMyEnum).ToString());
}
Now I would this that I could only call my myMethod passing only one of these three parameters: myEnum.SR0, myEnum.SR1 or myEnum.SR2 but it appears I can call myMethod with any byte as a parameter (and even something that can be converted to byte without loss of accuracy like an int).

So is there any way, other than checking if the passed parameter is contained in the enum, to ensure that I am only passed a certain parameter?

Einar
Semper ubi sub ubi.
Next
Reply
Map
View

Click here to load this message in the networking platform