I'm currently reading the book C# 4.0 in a Nutshell, which by the way I think is an excellent book, even for advanced programmers to use as a good reference.
I was looking back on the chapters about the basics, and I came across a trick to tell if a certain value is defined in an Enum when using flagged enums.
The book states that using Enum.IsDefined
doesn't work on flagged enums, and suggests a work-around like this :
static bool IsFlagDefined(Enum e)
{
decimal d;
return (!decimal.TryParse(e.ToString(), out d);
}
This should return true if a certain value is defined in an enum which is flagged.
Can someone please explain to me why this works ?
Thanks in advance :)