Assert sends a strong message to the developer. An assertion interrupts normal operation of the program but does not terminate the application.
The Debug.Assert method in the System.Diagnostics class provides a way to implement this functionality quickly.
Program that uses Assert method [C#]
static class Program
static void Main()
int value = -1;
// If value is ever -1, then a dialog will be shown.
Debug.Assert(value != -1, "Value must never be -1.");
// If you want to only write a line, use WriteLineIf.
Debug.WriteLineIf(value == -1, "Value is -1.");
A. The dialog is displayed.
B. Message is written to the Output: Value is -1.