For C# in VS2005, is there way to check if an integer is part of a Enum type?
eg:
if number in CustomerType { ... }
where
enum CustomerType
{
A = 0;
B = 1;
C = 2;
}
For C# in VS2005, is there way to check if an integer is part of a Enum type?
eg:
if number in CustomerType { ... }
where
enum CustomerType
{
A = 0;
B = 1;
C = 2;
}
Is Enum.IsDefined(Type enumType, Object value) what you're looking for?
Instead of your if-statement:
if (Enum.IsDefined(typeof(CustomerType), number))
{
...
}
Try something like this:
var value = Enum.GetName(typeof(CustomerType), 3); // instead of 3 you can use any value
where CustomerType
is:
public enum CustomerType
{
A = 0,
B = 1,
C = 2,
}
By passing 3 value will have a null value. If you pass an existing value (i.e. 0, 1 or 2) then you'll get "A", "B" or "C".
For further info you can check the static methods of the System.Enum
class.
Regards...