C# and Preprocessor macro

hello,

i'm a newbie with C# and i'd like to Preprocessor macro like I do with my C compiler how can I do that is it possible

example

#define STEP1 0x01

#define STEP2 0x02

void Function(int Choice)

{

switch(Choice)

{

case STEP1 :

break;

case STEP2:

break;

}

}




Answer this question

C# and Preprocessor macro

  • Francis Shanahan

    James Curran wrote:
    You cannot use an #define for that. However, consts will work.

    const int STEP1 = 0x01;
    const int STEP2 = 0x02;
    (the rest is the same)

    The C# preprocessor simply allow you to perform "conditional compiling". Using consts is much more effective than using symbol constants as it usually done in C world.


  • R0nda

    You cannot use an #define for that. However, consts will work.

    const int STEP1 = 0x01;
    const int STEP2 = 0x02;
    (the rest is the same)



  • MCP_SS

    you can't use C# preprocessor directive as the ones in C++, you can use it to include or exclude codes from compilation on a certain codition
    example
    #if debug
    // Some code
    #elif release
    //Some other code
    #else
    //some other code
    #endif


  • Wellnow

    Sadly no... the preprocessor support in C# does not support this kind of value replacement as is supported in C and C++, instead in C# its support is pretty much limited to conditional compilation ala:

    #define MySymbol

    int DoSomething()

    {

    #if MySymbol

    //Is included into build

    return 10;

    #else

    //Is NOT included into build

    return 20;

    #endif

    }



  • C# and Preprocessor macro