Lets say we have defined Planets
enum:
public enum Planets
{
Sun = 0,
Mercury=5,
Venus,
Earth,
Jupiter,
Uranus,
Neptune
}
I was using Enum.IsDefined
method for finding whether string exists in enum or not.
Enum.IsDefined(typeof(Planets), "Mercury"); // result is true
But, then I tried this and it returned true also:
Enum.IsDefined(typeof(Planets), 5); // result is true again
How, it comes? This method has not any overload. It has only one signature:
Enum.IsDefined(Type enumType, object value);
Why and how is Enum.IsDefined
searching for both name and value? And it is really interesting to me, why did they chosed that way? IMO making overloads would be better choice, not?