Conditional compilation

suggest change

The function below returns a different string depending on which symbols are defined at compile time.

// Compile with /d:A or /d:B to see the difference
string SomeFunction() 
{
#if A
    return "A";
#elif B
    return "B";
#else
    return "C";
#endif
}

Conditional compilation is typically used to log additional information for debug builds.

void SomeFunc()
{
    try
    {
        SomeRiskyMethod();
    }
    catch (ArgumentException ex)
    {
        #if DEBUG
        System.Diagnostics.Debug.WriteLine(ex);
        #endif

        HandleException(ex);
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents