- Home /
Does Mono evaluate equality of objects differently then MS .NET
Hello.
I have a generic container that has a past and present value stored as objects.
The container currently has bool types. Past and present are both true.
object a = past;
object b = present
bool same = a == b;
in the Visual Studio debugger I see the following in the watch window
a -> shows true
b -> shows true
a == b -> shows true
same =-> shows false
However, if I use .Equals instead of equality I get
a -> shows true
b -> shows true
a == b -> shows true
same -> shows true
So my question is:
Is there a very critical difference between the Mono and MS Runtime? Is there a bug in the watch window of the VS debugger?
Thanks!
Answer by fafase · Nov 05, 2015 at 08:31 AM
When you run
a == b
this performs a reference check since you have object type, regardless the content.
When you use Equals, you test the content of the object.
Right, but why does a == b show true in the inspector and false when executed through the runtime. Do you think this is a bug within Visual Studio? (See screenshot)
This came about me debugging a 3rd party package named uFrame, and I unrolled the equality check for testing. Until then I had no idea that LastValue and ObjectValue were objects. So the watch window reporting something different than the code was very confusing.
If you performs an if statement, do you get the wrong behaviour?
It would look like the expression is reporting the wrong type of check. It seems to show the content test ins$$anonymous$$d of the object reference test.
There has been some reports on VS debugger showing wrong. $$anonymous$$aybe you are one fo those as well.
Where would you like me to perform the if statement?
The result of this call is used in an if statement, and its what you described (a != b).
I should add that the code used to be
return property.PastValue != property.ObjectValue
and it would always return false as expected (once I knew PastValue and ObjectValue were objects
I'll file a VS bug. Thanks so much for your time
I should add that the code used to be
return property.PastValue != property.ObjectValue
and it would always return false as expected (once I knew PastValue and ObjectValue were objects
Your answer
![](https://koobas.hobune.stream/wayback/20220612043936im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unable to import items from package manager - Unable to get local issuer certificate 0 Answers
Internal Compiler Error 3 Answers
Visual Studio error for referenced scripts 2 Answers
How to make .shader open in Mono Develop, but C# still open in Visual Studio 0 Answers
,VS2017 cannot find Metadata file "Unity.TextMeshPro.Tests.dll" 0 Answers