Debugger Browsable Attribute in C#

DebuggerBrowsable is an attribute available to C# language. This attribute is helpful for determining the display of properties and fields.


Let’s consider following Employee class.


The following are the displays you usually see without adding the attribute.


Let’s add the attribute. You need to add reference to System.Diagnostics namespace.


Notice that, it takes an enum as parameter.


The DebuggerBrowsableState enum has following values.


Using this attribute other than Property, Index, and Field would give you following error.


Let’s add the following DebuggerBrowsable attribute to the Age property.


At debug time, notice that Age property is not available.

To use another DebuggerBrowsableState let’s add another property which is an array type such as AbsentDays.


Debugging the code displays the usual way of the array name and it’s values on expanding.


Now we would add the RootHidden enum type of DebuggerBrowsableState to AbsentDays property.


Notice that, the property name is not displayed and the children are expanded by default.


This is again very useful, if you have many properties and you need to check few of them. It saves time to drill down.


Thanks for reading. Like Method Of Tried in Facebook.