C# 调试(上) 预处理指令

xiaoxiao2021-02-28  86

1)禁止编译代码的某一部分

#define Debug #define Release #undef Debug using UnityEngine; using System.Collections; public class MyDebug : MonoBehaviour {     void Start()     { #if Debug && Release == false         print(Debug&&Release"不同时存在"); #elif Debug && Release         print("同时存在Debug&&Release是不允许的"); #elif (!Debug) || Release         print("只存在Release版本"); #else          print("两个版本都不存在"); #endif     } } 2) #warning 提醒自己要去做某事,或做过的事 #error  检查#define 是否出错 #define Debug #define Release //#undef Debug using UnityEngine; using System.Collections; public class MyDebug : MonoBehaviour {     void Start()     {         #region  此处用于讲解#define Debug,#if  #elif #else  #endif  #warning  #error #if Debug && Release == false         print(Debug&&Release"不同时存在"); #elif Debug && Release #error"同时存在Debug&&Release是不允许的" #elif (!Debug) || Release         print("只存在Release版本"); #else         print("两个版本都不存在"); #endif #warning "别忘了把下面的语句注释掉"         print("I hate my Boss!"); #endregion     } }

转载请注明原文地址: https://www.6miu.com/read-61963.html

最新回复(0)