codetale

i want to check whether the enum are in valid range or not
enum Test : byte{
e0 = 0,
e1 = 1,

e5 = 5,
e6 = 6
}
i convert the input into enum:Test by
byte b = (byte)input;
Test e = (Test)b;

ok, here the problem, no matter what is the value of b, the operation still success even the value of b are not in range of enum:Test(assume 4 or 7)

is there any way to check if the value are in valid range

thank you


Re: Visual C# General enum

Thomas Koelle

You should decide on using an array or an enum.

if you stick with enum try to work with e >= Test.e0 etc.

if you work with an array what you want is possible.

guess that makes it a no to your question.





Re: Visual C# General enum

codetale

no, i cant use array, because those "enum" was actually a part of my file header(in binary)
and the number are not "sort" because i might/will extend them in future.

thank you.

i found how to make it
Enum.IsDefined()