Tom,
There are no runtime checks performed on assignments to Enum, 10 may be a
valid value in that the enum may be a bit mask.
[Flags] enum testFlags = { a = 1, b = 2, c = 4, d = 8 }
10 would represent the value which include both b & d.
You can use the System.Enum.IsDefined to ensure that the value is a valid
enum amount.
Hope this helps
Jay
Tom Clement said:
I have a related question. I wrote the following code:
enum testEnum {a = 1, b = 2, c = 3}
private void TestIt()
{
int z = 10;
testEnum t = (testEnum)z;
Debug.WriteLine(t.ToString();
}
When I call TestIt(), no exception is thrown and the WriteLine sends
"10"
to
the output window. This seems wrong to me, as I'd expect a runtime
exception to be thrown when the assigned value isn't a member of the enum.
Perhaps it's just to costly to check? Thoughts?
Tom Clement
Apptero, Inc.
Hi Jay
That works great if you can guarantee the value to always be a