In C#, the Object.ReferenceEquals
method is
used to compare two reference type
variables. If you use this method to compare two value types, such as int
,
float
, or bool
you will not get the expected results because value type variables contain an instance of the type and not a
reference to it.
Due to value type variables containing directly an instance of the type, they can’t have the same reference, and using
Object.ReferenceEquals
to compare them will always return false
even if the compared variables have the same value.