DEV Community

Cover image for Show properties of an object during the debug
Emanuele Bartolesi
Emanuele Bartolesi

Posted on

Show properties of an object during the debug

During the debug sessions, very often, you have to check what is inside a property or in multiple properties.
It's very annoying every time to move the cursor on the object -> add to Quickwatch or try to click close to the arrow to see the values inside.

You can easily solve this problem with Visual Studio and improve your productivy during the debug.

The DebuggerDisplay attribute

For instance, you have this class with two properties inside.

    public class Person
    {
        public string Name { get; set; }

        public string Surname { get; set; }
    }
Enter fullscreen mode Exit fullscreen mode

You can tell to the debugger: "ehy, I want to see the values of these two properties".
You can simply add the DebuggerDisplay attribute on top of the class and you can format the string to display.

[DebuggerDisplay("Name = {Name} - Surname = {Surname}")]
Enter fullscreen mode Exit fullscreen mode

In the screenshot below, you can see the result.

Image description

If you want to go more deeper on the DebuggerDisplay attribute, this is the official documentation: https://docs.microsoft.com/en-us/visualstudio/debugger/using-the-debuggerdisplay-attribute?view=vs-2022

Top comments (0)