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:

Top comments (0)

Become a Moderator Do you want us to help make DEV a better place?

Fill out this survey and help us by becoming a tag moderator here at DEV.