-2

I use the latest Visual Studio Code on Ubuntu 19.04 for .Net Core 2.2 C# development. It ignores the #if false code-block comment-out. What do I miss? Thanks.

#if false
    Console.WriteLine("Don't run this line");
#endif

But it runs and it not commented out in the IDE editor.

Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
  • The code block is not commented out as expected. Debug still runs the code-block inside the `#if false #endif` – Kok How Teh May 24 '19 at 08:01
  • `#if false` to comment out a code block. What do you mean "comment out an `#if false`"? – Kok How Teh May 24 '19 at 08:05
  • `#if false` doesn't comment out anything, it hides that part completely from the compiler. Are you saying that this line compiles and runs, or that VS Code doesn't display it in gray? The first is a serious compiler issue. The second a syntax coloring issue – Panagiotis Kanavos May 24 '19 at 10:30
  • It doesn't grey it out. – Kok How Teh May 24 '19 at 13:16

1 Answers1

0

Using the line #if true/false will comment out the region below it (until #endif) if the condition is false. E.g:

#if false
Console.WriteLine("Hello");
#endif
Console.WriteLine("World!");

Will comment out the first writeline statement and only print "World!".

Max
  • 434
  • 1
  • 3
  • 13