While trying to implement a simple singly linked list in C#, I noticed that ==
does not work while comparing two object type variables boxed with an int value b
The operator ==
is like an overloaded static function selected based on the compile time types. In your case the type of the values is Object
, for which the ==
operator implements reference equality.
On the other hand .Equals
is virtual and overridden, so it will do the comparison based on the actual types.