2

I need the following logic

#if (DEV || QA || RELEASE)
//add when dev or qa or release configuration
#endif

Is it possible in c#?

Pavel
  • 1,015
  • 3
  • 13
  • 27

3 Answers3

6

Yes. Quoting the #if documentation on MSDN:

You can use the operators && (and), || (or), and ! (not) to evaluate whether multiple symbols have been defined. You can also group symbols and operators with parentheses.

clcto
  • 9,530
  • 20
  • 42
2
#define DEBUG 
#define MYTEST
using System;
public class MyClass 
{
    static void Main() 
    {
#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
    }
}

Here simple code how to do it. You can read full documentation on C# Preprocessor Directives

mybirthname
  • 17,949
  • 3
  • 31
  • 55
  • Is it possible to do this in cshtml file? – Pavel Dec 17 '14 at 06:03
  • 1
    @PavelIvanov you can check this question: http://stackoverflow.com/questions/4696175/razor-view-engine-how-to-enter-preprocessorif-debug. There are various ways to do it, you can check best method suited for you. – mybirthname Dec 17 '14 at 06:11
0

Yes. These are called "preprocessor directives" or compiler directives.

Reddog
  • 15,219
  • 3
  • 51
  • 63