Compartir a través de


Side Effects and Expressions

A side effect occurs when evaluating an expression changes the value of data in your application.

Side effects are something to watch for if you are evaluating expressions in the debugger. If you evaluate an expression in the Watch window or the QuickWatch dialog box and the expression has side effects, you might change the value of variables in another part of your program without realizing it. Side effects can make debugging more difficult by creating the appearance of bugs where none exist or masking the appearance of real bugs.

One common cause of side effects is evaluating a function call in a debugger window. Such evaluations are usually noticeable. A more subtle cause of side effects is the evaluation of properties and other implicit function calls in managed code.

The debugger cannot tell whether a property evaluation or implicit function call has side effects. Therefore, by default, the debugger does not evaluate implicit function calls automatically. Property evaluation is allowed by default, but can be turned off in the Options dialog box. When a function call or property has not been evaluated, a refresh icon appears. You can manually evaluate the expression by clicking the refresh icon. For details, see How to: Refresh Watch Values.

When evaluation of properties or implicit function calls is turned off, you can force evaluation by using the ac format modifier (for C# only). See Format Specifiers in C#.

See Also

Tasks

How to: Refresh Watch Values