Using Assertions Within an Application

The .NET Compact Framework also supports a Trace class, which is in effect for both debug and release builds. In the .NET Compact Framework, this class supports only the Assert method and does not support full tracing the way the full .NET Framework counterpart does.

using System.Diagnostics;
⋮
Trace.Assert(bean.IsMagic, "This is not a magic bean");

In this example, if the assertion is true, nothing is displayed. If bean.IsMagic is false, the dialog box shown in Figure 5-13 appears.

Managed Assert Failure dialog box.

Figure 5-13. Managed Assert Failure dialog box.

The Abort button terminates the application. The Retry button will try to connect ...

Get Microsoft® .NET Compact Framework (Core Reference) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.