Debug.Listeners : Debug « System.Diagnostics « C# / C Sharp by API






Debug.Listeners

  
// compile with: csc /r:system.dll file_1.cs

using System;
using System.Diagnostics;

class MyClass
{
    public MyClass(int i)
    {
        this.i = i;
    }
    
    [Conditional("DEBUG")]
    public void VerifyState()
    {
        Debug.Assert(i == 0, "Bad State");
    }
    
    int i = 0;
}

public class DefensiveProgrammingAsserts
{
    public static void Main()
    {
        Debug.Listeners.Clear();
        Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
        MyClass c = new MyClass(1);
        
        c.VerifyState();
    }
}

   
    
  








Related examples in the same category

1.Debug.Assert
2.Debug.Fail
3.Debug.WriteLine