How to Create Conditional method

Waqas Anwar
29 August 2012
4904 Views

If you want to execute some methods conditionally only in debug mode then you can decorate the method with the Conditional attribute as follows:

First of all import System.Diagnostics namespace
using System.Diagnostics;Then add Conditional attribute to the method you want to execute only in debug mode.
[Conditional("DEBUG")]
public static void SomeMethod()
{
   Console.WriteLine("You are in debug mode");
}