Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Trace.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 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 to see that 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)
    Trace.Assert( Not (type Is Nothing), "Type parameter is null", _
        "Can't get object for null type")

    ' Perform some processing.
End Sub


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


[C++] 
public:
   static void MyMethod(Type* type, Type* baseType) {
      Trace::Assert(type != 0, S"Type parameter is null",
         S"Can't get object for null type");

   // Perform some processing.
}


[JScript] 
import System
import System.Diagnostics

var obj
var type : Type

Trace.Assert(obj != null, "obj variable is null", "Can't get type for null object")
type = obj.GetType()
print(type.ToString())

See Also

Trace Class | Trace Members | System.Diagnostics Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft