❔ Where can I find the implementation of System.Object.ReferenceEquals?
I'd like to know how the reference comparison works under the hood but I've never looked up the source code of .NET classes before so please help me with that.
10 Replies
Thank you!
So it shows the following implementation
public static bool ReferenceEquals(object? objA, object? objB)
{
return objA == objB;
}
Now that doesn't really explain much, where should I go next?What did you expect it to explain?
I want to know what is exactly going on. Where is the reference taken from? What does it look like? Etc.
The reference is... the reference. A pointer, in C# terms
When it comes to reference types, that's what gets compared
If
objA
is at 0x68FD312
in memory, and objB
is also at 0x68FD312
, they're equalhow does .NET runtime know that the identifier objA and the address 0x68FD312 are related?
No clue tbh
It's way too low level to be useful to know
But if you want to know about implementation details like that, #allow-unsafe-blocks is where you can probably get your answers
People who work on the compiler and the framework itself hang around there
thank you 👍
There probably is some internal table that has addresses in one column and identifiers in the other one
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.