Sometimes when working with C# you discover some hidden gems. Some of them very useful, other ones a little bit harder to find a good way to benefit from their functionality. One of those hidden gems that I discovered some days ago are Expression Evaluator Format Specifiers.
What is it?
Expression Evaluator Format Specifies come into the picture when you are debugging in Visual Studio. The part of the debugger that processes the language being debugged is known as the expression evaluator (EE). A different expression evaluator is used for each language, though a default is selected if the language cannot be determined.
A format specifier, in the debugger, is a special syntax to tell the EE how to interpret the expression being examined. You can read about all of the format specifiers in the documentation.
One of really useful format specifiers is the ‘ac’ (always calculate) format specifier. This format specifier will force evaluation of the expression on every step. This is useful during debugging when you want to track a specific value.
How to use it?
- Start a debugging session in your application.
- Go to the Watch window(Debug –> Windows –> Watch –> Watch 1)
- Write the expression that you want to check, a comma and the format specifier; {expression},{format specifier}
- If you use the ac format specifier you don’t have to refresh your expression but will it be evaluated on every step: