开发者

C# #if / #ifdef syntax doesn't compile, why?

开发者 https://www.devze.com 2023-01-13 05:35 出处:网络
Why does the below code not compile (snippet) ? public enum ApplicationType : int { CONSOLE = 1, WINDOWS_FORMS = 开发者_StackOverflow中文版2,

Why does the below code not compile (snippet) ?

  public enum ApplicationType : int
  {
   CONSOLE = 1,
   WINDOWS_FORMS = 开发者_StackOverflow中文版2,
   ASP_NET = 3,
   WINDOWS_SERVICE = 4,
   MUTE = 5
  }

        //#if( false)
        //#if (DEBUG && !VC_V7)
 #if( m_iApplicationType != ApplicationType.ASP_NET  )
        public class HttpContext
  {
   public class Current
   {
    public class Response
    {
     public static void Write(ref string str)
     {
      Console.WriteLine(str);
     }
    }
   }
  }
#endif


What error are you getting?

In any case, ( m_iApplicationType == ApplicationType.ASP_NET ) is not a compile time constant.


Your use of #if with a member variable is invalid. It operates only on symbols that you create with the #define directive, like so:

#define ASP_NET

#if(ASP_NET)
// put your conditional compilation code here
#endif

#if(CONSOLE)
// your console-related code goes here
#endif

In this case, only the code within the #if(ASP_NET) block will be compiled because CONSOLE is not defined.

0

精彩评论

暂无评论...
验证码 换一张
取 消