DebuggerDisplay Attribute in C#

The DebuggerDisplay is useful to quickly view the customized output of a class which in turn can display more meangful text during debugging.

Below is an example. Assume the class Student contains the following properties

class Student

{

   public string Name {get;set;}
   public string RegNo {get;set;} 
}

An instance of the student object is created and assigned values like below

public MainPage()

{

   Student name = new Student();

   name.Name = "Senthil Kumar";

   name.RegNo = "06PG0225";

}

During debugging, just mouse over on the instance “name”, you should see the data as shown in the screenshot below.

In the above screenshot, you will see a + icon followed by the instance name and the type.

Now, modify the class to include the DebuggerDisplay attribute like the one shown below.

Now, follow the same steps as described above. You should see a more meaningful data now 🙂

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...