Code Snippet
class Program
- {
- static void Main(string[] args)
- {
- # if DEBUG
- Console.WriteLine("Application starts in debug mode");
- # else
- Console.WriteLine("Application starts NOT in debug mode");
- # endif
- SayHelloOnlyInDebug();
- Console.ReadLine();
- }
- [Conditional("DEBUG")]
- private static void SayHelloOnlyInDebug()
- {
- Console.WriteLine("Hello!");
- }
- }
And what is different between proprocessor directive and Conditional Attribute?
Proprocessor directive - the statement in #if #else is compiled conditionally dependent upon thepresence of the DEBUG symbol.
Proprocessor directive - the statement in #if #else is compiled conditionally dependent upon thepresence of the DEBUG symbol.
Conditional Attribute - You might feel more comfortable with the Conditional attribute, which can be used to exclude entire methods, without needing to complicate the source with conditionals on the calling side.