Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Verify thatvalue is an enum member
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01036221
Message ID:
01036225
Vues:
8
Snooping around in the Enum class gave me the solution:
MessageBox.Show(System.Enum.IsDefined(typeof(myEnum), paraEnum).ToString());
Einar
>I know I have read this somewhere but I can't seem to find that article at the moment.
>Considder the following example:
>
>private void button1_Click(object sender, System.EventArgs e)
>{
>	myMethod(myEnum.two);
>	myMethod((myEnum)0xDD);
>}
>private void myMethod(myEnum paraEnum)
>{
>	MessageBox.Show(paraEnum.ToString());
>}
>public enum myEnum: byte
>{
>	one = 0x01,
>	two = 0x02,
>	ff = 0xff
>}
>
>
>I want to pass an enum as a parameter to a method, but the first thing I want to check for in the method is if it is a valid enum(i.e. an enum member).
>
>Any thoughts?
>
>Einar
Semper ubi sub ubi.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform