Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
Reference
System.Diagnostics
Debug Class
Methods
Assert Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
.NET Framework Class Library
Debug.Assert Method

Checks for a condition and displays a message if the condition is false.

Overload List

Checks for a condition and outputs the call stack if the condition is false.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Assert(Boolean)
[C#] public static void Assert(bool);
[C++] public: static void Assert(bool);
[JScript] public static function Assert(Boolean);

Checks for a condition and displays a message if the condition is false.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Assert(Boolean, String)
[C#] public static void Assert(bool, string);
[C++] public: static void Assert(bool, String*);
[JScript] public static function Assert(Boolean, String);

Checks for a condition and displays both specified messages if the condition is false.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Assert(Boolean, String, String)
[C#] public static void Assert(bool, string, string);
[C++] public: static void Assert(bool, String*, String*);
[JScript] public static function Assert(Boolean, String, String);

Example

The following example checks whether the type parameter is valid. If the type passed in is a null reference (Nothing in Visual Basic), the Assert outputs a message.

[Visual Basic] 
Public Shared Sub MyMethod(type As Type, baseType As Type)
    Debug.Assert( Not (type Is Nothing), "Type parameter is null", "Can't get object for null type")
    ' Perform some processing.
End Sub 'MyMethod

[C#] 
public static void MyMethod(Type type, Type baseType) {
    Debug.Assert(type != null, "Type parameter is null", 
       "Can't get object for null type");
 
   // Perform some processing.
 }


[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

void SomeMethod(Object * obj, Type * type);

int main(void)
{
    SomeMethod(0, 0); 

    return 0;
}

void SomeMethod(Object * obj, Type * type)
{
    Debug::Assert(type, S"type paramater is null", S"Can't get object for null type");
}


[JScript] 
public static function MyMethod(type : Type, baseType : Type) {
    Debug.Assert(type != null, "Type parameter is null", 
       "Can't get object for null type");
 
   // Perform some processing.
 }

See Also

Debug Class | Debug Members | System.Diagnostics Namespace

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker