C
C#15mo ago
mikeitsme

❔ 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
mikeitsme
mikeitsmeOP15mo ago
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?
Angius
Angius15mo ago
What did you expect it to explain?
mikeitsme
mikeitsmeOP15mo ago
I want to know what is exactly going on. Where is the reference taken from? What does it look like? Etc.
Angius
Angius15mo ago
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 equal
mikeitsme
mikeitsmeOP15mo ago
how does .NET runtime know that the identifier objA and the address 0x68FD312 are related?
Angius
Angius15mo ago
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
mikeitsme
mikeitsmeOP15mo ago
thank you 👍
Angius
Angius15mo ago
There probably is some internal table that has addresses in one column and identifiers in the other one
Accord
Accord15mo ago
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.
Want results from more Discord servers?
Add your server