When debugging I sometimes find the need to compare object references in the watch window to see if two variables are actually referencing the same object.
With C++ and pointers this is easy, but is there any way of doing this with C# references?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is actually a built in feature for comparing objects in the Watch window that doesn’t require you to call any functions directly. It’s in the right click menu as “Make Object ID”
It will mark the object with an ID, and then you can add a second object and mark it with an id as well. If those object are the same reference, then they will have the same ID. This allows you to see if/when they change as you are debugging.