Logo

Programming-Idioms

History of Idiom 123 > diff from v25 to v26

Edit summary for version 26 by programming-idioms.org:
[C#] 2 ways => 2 impls, see new impl 4116

Version 25

2020-09-07, 08:15:59

Version 26

2020-09-07, 08:16:53

Idiom #123 Assert condition

Verify that predicate isConsistent returns true, otherwise report assertion violation.
Explain if the assertion is executed even in production environment or not.

Idiom #123 Assert condition

Verify that predicate isConsistent returns true, otherwise report assertion violation.
Explain if the assertion is executed even in production environment or not.

Variables
isConsistent
Variables
isConsistent
Imports
using System.Diagnostics;
Imports
using System.Diagnostics;
Code
var result = isConsistent();

// Debug assertion (removed from Release builds)
Debug.Assert(result);

// Trace assertion (included in Release builds)
Trace.Assert(result);
Code
var result = isConsistent();
Debug.Assert(result);
Comments bubble
It is considered unsafe to call a function directly in a debug assertion because any side-effects in the function won't affect Release builds.
Comments bubble
Debug assertion (removed from Release builds).
It is considered unsafe to call a function directly in a debug assertion because any side-effects in the function won't affect Release builds.
Doc URL
https://docs.microsoft.com/en-us/visualstudio/debugger/assertions-in-managed-code
Doc URL
https://docs.microsoft.com/en-us/visualstudio/debugger/assertions-in-managed-code