Part of the System.Diagnostic namespace, Debug.Assert() is used to
display the Call Strack Trace and it gives you three options – ‘Abort’,
‘Retry’ and ‘Ignore’. Basically when Debug.Assert() receives the
boolean parameter false a dialog box pops up giving you details with
Call Stack, and you can either end the program or continue.
One example of where you can use Debug.Assert() is when checking
if a file exists:
System.Diagnostics.Debug.Assert(System.IO.File.Exists(FileName)); |
If the file doesn’t exist File.Exists() will return false, and (as mentioned earlier) when you pass this boolean value to Debug.Assert(), the Call Strack Trace dialog box pops up.
If you want you can test Debug.Assert() by directly passing the false parameter:
System.Diagnostics.Debug.Assert(false); |