Writes the name of the value parameter to the trace listeners in the Listeners collection if a condition is true.
[Visual Basic] Overloads Public Shared Sub WriteIf( _ ByVal condition As Boolean, _ ByVal value As Object _ ) [C#] public static void WriteIf( bool condition, object value ); [C++] public: static void WriteIf( bool condition, Object* value ); [JScript] public static function WriteIf( condition : Boolean, value : Object );
By default, the output is written to the managed code debuggers, the Microsoft.Win32.Interop.Windows.OutputDebugString API and to the Log method.
Notes to Implementers: You can minimize the performance penalty of instrumenting your application by using If...Then statements instead of using WriteIf statements. The following two code examples send the same debugging message. However, the first example is much faster when tracing is off, because if mySwitch.TraceError evaluates to false you do not call Write. The second example always calls WriteIf, even when mySwitch.TraceError is false and no tracing output is produced. This can result in unnecessary execution of an arbitrarily complex code.
First example.
if(mySwitch.TraceError) Debug.Write("aNumber = " + aNumber + " out of range");
Second example.
Debug.WriteIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");
Debug Class | Debug Members | System.Diagnostics Namespace | Debug.WriteIf Overload List | Debug | Trace | BooleanSwitch | TraceSwitch | TraceListener | DefaultTraceListener | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute