Indent, Unindent

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:Tutorials
C# Tutorials
Testing and Debugging
edit

Contents

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


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();
      }
    }
  }
}

Result

Image:indent.gif


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.


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");
      }
    }
  }
}

Result

Image:writecat.gif


Personal tools