Preprosessor directives

Preprosessor directives mark the code block for compiler.

For example,


#define DEBUG
using System;
class MyClass
{
    int x;
    void aMethod()
    {
# if DEBUG
        Console.WriteLine("Testing: x = {0}", x);
# endif
    }

}

If DEBUG is defined C# will compile the statement.

We can supply the flag with /define:Symbol through commandline.

The following table lists all C# Preprosessor directives

Preprocessor directiveAction
#define symbolDefines symbol
#undef symbolUndefines symbol
#if symbol [operator symbol2]... operators are ==, !=, &&, and || followed by #else, #elif, and #endif
#elseExecutes code to subsequent #endif
#elif symbol [operator symbol2]Combines #else branch and #if test
#endifEnds conditional directives
#warning textwarning text for compiler output
#error texterror text for compiler output
#line [ number ["file"] | hidden]number specifies the line in source code; file is the filename to appear in computer output; hidden instructs debuggers to skip over code from this point until the next #line directive
#region namebeginning of an outline
#end regionEnds an outline
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.