Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using enum as a parameter
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Using enum as a parameter
Divers
Thread ID:
00971423
Message ID:
00971423
Vues:
63
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.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform