Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0222 Conditional attributes

Conditional attributes tell the compiler to ignore a call to a method or a class if the flag is not defined. #define TESTMODE using System; using System.Diagnostics; class Program { static void Main() { Console.WriteLine("in test mode!"); // OUTPUT: in test mode! } [Conditional("LOGON")] static void YourMethod(string msg) { } } The output: in test mode!