Skip to content

Latest commit

 

History

History
74 lines (61 loc) · 4.1 KB

format-specifiers-in-csharp.md

File metadata and controls

74 lines (61 loc) · 4.1 KB
titledescriptionms.datems.topicdev_langshelpviewer_keywordsauthorms.authormanagerms.subservice
Format specifiers in the debugger (C#)
Use a format specifier to change the format in which a value is displayed in the Watch window. This article provides usage details.
11/21/2018
conceptual
CSharp
VB
FSharp
C++
expressions [C#], formatting values
variables [debugger], watch variable symbols
symbols, watch variable formatting
QuickWatch dialog box, using format specifiers
specifiers, watch variable format
QuickWatch dialog box, format specifiers in C#
specifiers
watch variable symbols
Watch window, format specifiers in C#
format specifiers, debugger
debugger, format specifiers recognized by
mikejo5000
mikejo
mijacobs
debug-diagnostics

Format specifiers in C# in the Visual Studio debugger

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

To use a format specifier, enter the variable expression followed by a comma and the appropriate specifier.

Set format specifiers

We'll use the following example code:

{intmy_var1=0x0065;intmy_var2=0x0066;intmy_var3=0x0067;}

Add the my_var1 variable to the Watch window while debugging, Debug > Windows > Watch > Watch 1. Next, right-click the variable and select Hexadecimal Display. Now the Watch window shows the value 0x0065. To see this value as a decimal integer rather than a hexadecimal integer, add the decimal format specifier , d in the Name column after the variable name. The Value column now shows 101.

Screenshot of the Visual Studio Watch window with one line that shows my_var1, d with a value of 101 and a type of int.

::: moniker range=">= vs-2019"

You can view and select from a list of available format specifiers by appending a comma (,) to the value in the Watch window.

FormatSpecCSharp

::: moniker-end

Format specifiers

The following table describes the C# format specifiers for the Visual Studio debugger.

SpecifierFormatOriginal Watch ValueDisplays
acForce evaluation of an expression, which can be useful when implicit evaluation of properties and implicit function calls is turned off.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
nseSpecifies behavior, not format. Evaluates the expression with "No side effects". If the expression can’t be interpreted and can only be resolved by an evaluation (such as a function call), you will see an error instead.N/AN/A
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 membersDisplays the members the meet the conditions of the query

Related content

close