预处理指令

本文通过一个具体的C#示例介绍了如何使用预处理器指令,包括 #undef、#elif 和 #else,展示了这些指令如何在代码中根据不同的条件执行不同的操作。

/*
  Example4_17.cs illustrates the use of the
  #undef, #elif, and #else preprocessor directives
*/

#define DEBUG
#undef DEBUG
#define PRODUCTION

class Example4_17
{

  public static void Main()
  {

    int total = 0;
    int counter = 0;

    myLabel:
    counter++;
    total += counter;
    System.Console.WriteLine("counter = " + counter);
    if (counter < 5)
    {
#if DEBUG
      System.Console.WriteLine("goto myLabel");
#elif PRODUCTION
      System.Console.WriteLine("counter < 5");
#else
      System.Console.WriteLine("goto myLabel, counter < 5");
#endif
      goto myLabel;
    }

    System.Console.WriteLine("total = " + total);

  }

}

转载于:https://www.cnblogs.com/djcsch2001/archive/2011/05/03/2035676.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值