No, the whole call, including evaluating the expression, is removed from compilation if the character is not defined. This is very important - if there are any side effects in the expression, they will not occur if DEBUG is not defined. Here's a short but complete program to demonstrate:
using System; using System.Diagnostics; class Test { static void Main() { int i = 0; Debug.Assert(i++ < 10); Console.WriteLine(i); } }
If DEBUG defined, it returns 1, otherwise it will print 0.
Because of this behavior, you cannot have an out parameter for a conditionally compiled method:
using System; using System.Diagnostics; class Test { static void Main() { int i ; MethodWithOut(out x); } [Conditional("FOO")] static void MethodWithOut(out int x) { x = 10; } }
This gives an error:
Test.cs (13,6): error CS0685: Conditional member 'Test.MethodWithOut (out int)' cannot have out parameter
Jon skeet
source share