C# - What does the Assert() method do? Is it still useful?

Pokus picture Pokus · Oct 2, 2008 · Viewed 160.4k times · Source

I am debugging with breakpoints and I realize the assert call? I thought it was only for unit tests. What does it do more than breakpoint? Since I can breakpoint, why should I use Assert?

Answer

Patrick Desjardins picture Patrick Desjardins · Oct 2, 2008

In a debug compilation, Assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

If you compile in Release, all Debug.Assert's are automatically left out.