C# 的 #if DEBUG使用

DEBUG+Assert调试代码还是不错。

int i = 10;
#if DEBUG
            Debug.Assert(i < 9,"条件不成立");
            WriteLine("DEBUG");
#else
      WriteLine("Release");
#endif

在Debug和Release模式下会分别执行不同的代码。

C# 的 #if DEBUG使用

Debug

C# 的 #if DEBUG使用

Release

C# 的 #if DEBUG使用
调试下断言如果不满足会弹一个提示框,忽略和中断,就结束了,重试会进入断点。可以加入自己写的错误提示

C# 的 #if DEBUG使用