Mahek
Menu

Fragrance
​of Programming

Visual Studio 2017 Tips: Debugger Display

10/20/2017

Comments

 
There are many hidden tricks which are present in Visual Studio 2017 and can be really very useful. And one of them which I will be discussing today is "DebuggerDisplay".
Debugger Display helps to display runtime object data in simple and meaningful way. Of course meaningful data differs from developer to developer and also depends on what we are debugging. At least Debugger display gives control what to display and with the help of attributed debugging.
Attributed debugging gives type the ability to specify what it looks like when being debugged. The simplest form of this is the DebuggerDisplayAttribute. Below is the sample code.

After writing the above code, set a breakpoint at the end of the Main class and if you watch "Employees" in Watch, you will see something as below:
Picture
Now if you want to examine any of the employee object you first need to know which object inside the Employees collection. You can even override ToString and display the complete name but that will be functional evaluation and will be very slower and also not necessary the ToString implementation and the Debug view is same. So in such case "DebuggerDisplay" comes very handy and you can use it as shown below

After attaching the above attribute in the Employee class, you can see that now Debug display more sensible data and it's very easy to locate the object in the collection.
Picture
Watch after applying the DebuggerDisplay attribute
If you want you can even include the format specifiers in the expression.

Comments

    RSS Feed

    Categories

    All
    Azure
    C#
    Cloud
    CodeProject
    CSharp
    DotNet Core
    Jetbrains
    .NET
    Rider
    SQL
    Tech News
    Ubuntu
    Visual Studio 2015
    Visual Studio 2019
    Windows
    Windows 10

    Archives

    January 2019
    December 2018
    May 2018
    December 2017
    November 2017
    October 2017
    September 2017
    July 2017
    May 2017
    April 2017
    May 2015
    April 2015
    March 2015

    View my profile on LinkedIn

Location

Contact Us

    Subscribe Today!

Submit
  • Blog
  • About
  • Contact
  • Random Clicks
  • Blog
  • About
  • Contact
  • Random Clicks