Use Conditional attributes instead of #if..#endif blocks

Home   »   Use Conditional attributes instead of #if..#endif blocks

#define TRACE_ON
using System;
using System.Diagnostics;

namespace AttributeExamples
{
    public class Trace
    {
        [Conditional("TRACE_ON")]
        public static void Msg(string msg)
        {
            Console.WriteLine(msg);
        }
    }

    public class TraceExample
    {
        public static void Main()
        {
            Trace.Msg("Now in Main...");
            Console.WriteLine("Done.");
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *