What is wrong with this code answer.
I asked what was going on there, and the answer is simple, really.
We put an enum (a struct, basically) into an object, which cause boxing, when we try to compare two objects that don't override the == operator, we get reference equality. Which means that the result from the code would be true.
However, the story grows more complex, put the following expression into VS.Net's watch window: "Value != defaultValue" the result would be false. Apparently the debugger is taking care of those little things like unboxing the values for you. That was very confusing until I figured out what was wrong.
The solution? Simple do this: defaultValue.Equals(Value)==false and it will work.
P.S:
My #1 wish for C# is that I could have a way to say not true instead of using punctuation to control it. This is the only problem that I've with using punctuation in C#, because all other forms are far more visible.
Comments
Comment preview