Format Specifiers in C#


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at Format Specifiers in C#.

You can change the format in which a value is displayed in the Watch window using format specifiers. You can also use format specifiers in the Immediate window, the Command window, and even in source windows. If you pause on an expression in those windows, the result will appear in a DataTip. DataTips will reflect the format specifier in the DataTip display.

To use a format specifier, type the expression followed by a comma. After the comma, add the appropriate specifier.

If you have the following code:

        int my_var1 = 0x0065;  
        int my_var2 = 0x0066;  
        int my_var3 = 0x0067;  

Add the my_var1 variable to the Watch window (while debugging, Debug / Windows / Watch / Watch 1) and set the display to hexadecimal (in the Watch window, right-click the variable and select Hexadecimal Display). Now the Watch window shows that it contains the value 0x0065. To see this value expressed as a decimal integer instead of a hexadecimal integer, in the Name column, after the variable name, add the decimal format specifier: , d. The Value column now displays the decimal value 101


The following table shows the C# format specifiers recognized by the debugger.

SpecifierFormatOriginal Watch ValueDisplays
acForce evaluation of an expression. This can be useful when implicit evaluation of properties and implicit function calls is turned off. See Side Effects and Expressions.Message “Implicit function evaluation is turned off by the user”<value>
ddecimal integer0x0065101
dynamicDisplays the specified object using a Dynamic ViewDisplays all the members of the object, including the Dynamic ViewDisplays only the Dynamic View
hhexadecimal integer615410x0000F065
nqstring with no quotes"My String"My String
hiddenDisplays all public and non-public membersDisplays public membersDisplays all members
rawDisplays item as it appears in the raw item node. Valid on proxy objects only.Dictionary<T>Raw View of Dictionary<T>
resultsUsed with a variable of a type that implements IEnumerable or IEnumerable<T>, usually the result of a query expression. Displays only the members that contain the query result.Displays all the members.Displays the members the meet the conditions of the query.

Watch and QuickWatch Windows
Variable Windows