WriteIf, WriteLineIf
From C# Online.NET (CSharp-Online.NET)—your free C# and .NET encyclopedia
| CSharp-Online.NET:Tutorials |
| C# Tutorials |
Testing and Debugging
|
| edit |
Debug.WriteIf and Debug.WriteLineIf allow you to only print debug if a certain state occurs.
Note: The following examples are not the same. The difference is that on the Release Build the if statement will still exsit if the latter code example is used.
Debug.WriteLineIf(test == true,"Here");
if (test == true) { Debug.WriteLine("Here"); }
[edit]
Example
using System; using System.Windows.Forms; using System.Diagnostics; namespace debugTesting { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void debugWrite_Click(object sender, EventArgs e) { int importantVariable = 4; for (int i = 0; i < importantVariable; i++) { Debug.WriteLineIf((i % 2 == 0),"Even number","Loop"); } } } }
[edit]
