Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When debugging, is there a way to tell if an object is a different instance?

When debugging, I was expecting two different classes to be using the same instance of an object. All of the properties were the same for these two objects, but they were two different instances. Is there a way to tell that in the VS debugger?

In order to tell for sure, I was able to add a field to the class:

private string someId = Guid.NewGuid().ToString(); 

Then, when debugging, I could at least look at that field for each of the two instances. Is there a better way that wouldn't involve having to create this dummy ID field?

like image 325
Bob Horn Avatar asked Mar 22 '13 19:03

Bob Horn


People also ask

How to see Data table values while debugging?

set the break point on the dataset/datatable(f9 shortcut key for break point) and run your application (f5 is the shortcutkey ) When the break point comes mouse hover the dataset/datatable click on the glass shown in the hover image in visual studio . Note : check compilation debug="true" is true in web config .

How to see variables when debugging in visual studio?

Hover over a variable to see its value. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

Which object can be used for debugging purpose?

Arduino Nano boards have in-build USB that is can be used for the debugging purpose.

How to see variable value while debugging in visual studio code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


2 Answers

When debugging, in the Locals window, right-click on the instance and select "Make Object ID".

This will add number that is unique for this instance which is displayed whenever you see this instance in the debugger (in tool-tips as well as in the watch window).

enter image description here

enter image description here

like image 50
Wolfgang Avatar answered Sep 22 '22 20:09

Wolfgang


Object.Equals Method (Object, Object)

Edit: To check reference equality use ReferenceEquals

Edit 2: While Debugging, Go to debug menu, windows --> immediate window (intellisense should work here) and ?Object.ReferenceEquals(obj1, obj2)

like image 22
Aseem Gautam Avatar answered Sep 23 '22 20:09

Aseem Gautam