Consider the following
public enum E
{
A = 1,
B = 1
}
public string F(E input)
{
return input.ToString();
}
F(E.B); //returns "A"
Now I know that you’re not supposed to do ((E)1).ToString(), as it could resolve to A or B (http://msdn.microsoft.com/en-us/library/16c1xs4z.aspx).
But when it’s an explicitly chosen value (e.g. B), why does ToString() behave wierdly (returning A)?
When debugging its possible to see that input is B, is it possible to get the selected field in code?
EDIT
This question relates to how the debugger knows which value is passed to F(), whilst in code it doesn’t seem possible to detect this?
The problem ist that the two possible enum values
AandBboth have an integer value of1, making it impossible to make the distinction betweenAandBsince C# just passes a value of1as argument to the method.