Defensive Programming : Assert Debug : Development Class C# Source Code


Custom Search

C# Source Code » Development Class » Assert Debug »

 

Defensive Programming








    


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







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Development Class
» Assert Debug