Indent, Unindent
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:Tutorials |
| C# Tutorials |
Testing and Debugging
|
| edit |
Contents |
[edit]
Indent - Unindent
Calling the Debug.Indent and Debug.Unindent methods simply change the indentation of the output. Maybe not the most useful, but certianly handy for picking out errors in repetitive code.
Note: you don't have to worry about sending too many unindents as it will stop at the margin without causing any errors
[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.WriteLine("Doing Stuff"); Debug.Indent(); } for (int i = 0; i < importantVariable; i++) { Debug.WriteLine("Doing Other Stuff"); Debug.Unindent(); } } } }
[edit]
Result
[edit]
Categories
Debug.Write, Debug.WriteLine, Debug.WriteIf and Debug.WriteLineIf all allow you to add a category string. This helps to tidy the debug output and make it more understandable.
[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.WriteLine("Doing Stuff","Loop 1"); } for (int i = 0; i < importantVariable; i++) { Debug.WriteLine("Doing Other Stuff","Loop 2"); } } } }
[edit]

