top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

What does assert() method do?

+2 votes
What does assert() method do?
posted Jul 29, 2014 by Khusboo

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
Best answer

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#]

using System;
using System.Diagnostics;

static class Program
static void Main()
int value = -1;
// A.
// If value is ever -1, then a dialog will be shown.
Debug.Assert(value != -1, "Value must never be -1.");

// B.
// 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.

answer Aug 13, 2014 by Amit Kumar Pandey
Similar Questions
+4 votes

How would you enable impersonation in the web.config file?

+4 votes

How to Generic Method to Create and Execute Parameterized SQL Query in .NET 4.0 ?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.