How to Create Conditional method

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.

public static void SomeMethod() 
   Console.WriteLine("You are in debug mode"); 



About author

User avatar

Waqas Anwar

Founder of, Senior Consultant, Microsoft .NET and Web Technologies