14
The #if is a pre-processing directive which allows you to pass parameters to the compiler.
When you do
#if false
...
#endif
The compiler understands that nay is to compile/interpret the #if
.
A more common use of this directive is:
#if DEBUG
Console.WriteLine("Olá mundo!");
#endif
Which will run the block only if the project is in DEBUG
.
The directive #if false
does not work as a comment.
Inside the comment you don’t need to respect the syntax of C#, for example,
the #if false
causes the compiler to delete everything from this compilation block but does not ignore it completely equal to a comment, so the compiler will still look at the text that is inside the block.
For example, the code below will generate an error:
#if false
#foo
#endif
Right, and what’s the real difference between #if false and you comment on the code block ?
– Thiago Loureiro
@Thiagoloureiro a lot. Pre-compilation things can be solved by adding headers, or by commands played to the pre-compiler
– Jefferson Quesado
In VB.NET,
#if
works as a comment.– CypherPotato