Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic


#undef lets you undefine a symbol, such that, by using the symbol as the expression in a #if directive, the expression will evaluate to false.

#undef symbol


The name of the symbol you want to undefine.


A symbol can be defined either with the #define directive or the /define compiler option. The #undef directive must appear in the file before you use any statements that are not also directives.


// preprocessor_undef.cs
// compile with: /d:DEBUG
#undef DEBUG
using System;
public class MyClass 
   public static void Main() 
      #if DEBUG
         Console.WriteLine("DEBUG is defined");
         Console.WriteLine("DEBUG is not defined");


DEBUG is not defined

See Also

C# Preprocessor Directives

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.