#if RELEASE 会像 C# 中的 #if DEBUG 那样工作吗? [英] Will #if RELEASE work like #if DEBUG does in C#?

查看:29
本文介绍了#if RELEASE 会像 C# 中的 #if DEBUG 那样工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看到的所有关于#if 编译器指令的示例中,它们都使用DEBUG".我可以以相同的方式使用RELEASE"来排除在调试模式下编译时不想运行的代码吗?我想用这个块包围的代码发送了一堆电子邮件,我不想在测试时不小心将它们发送出去.

In all the examples I've seen of the #if compiler directive, they use "DEBUG". Can I use "RELEASE" in the same way to exclude code that I don't want to run when compiled in debug mode? The code I want to surround with this block sends out a bunch of emails, and I don't want to accidentally send those out when testing.

推荐答案

不,不会,除非你做一些工作.

No, it won't, unless you do some work.

这里的重要部分是 DEBUG 的真正含义,它是一种定义为编译器可以检查的常量.

The important part here is what DEBUG really is, and it's a kind of constant defined that the compiler can check against.

如果您检查项目属性,在 Build 选项卡下,您会发现三件事:

If you check the project properties, under the Build tab, you'll find three things:

  • 标有条件编译符号"的文本框
  • 标有定义调试常量"的复选框
  • 标有定义跟踪常量"的复选框

没有这样的复选框,也没有预定义名为 RELEASE 的常量/符号.

There is no such checkbox, nor constant/symbol pre-defined that has the name RELEASE.

但是,您可以轻松地将该名称添加到标记为条件编译符号的文本框中,但请确保在执行此操作之前将项目配置设置为发布模式,因为这些设置是针对每个配置的.

However, you can easily add that name to the text box labelled Conditional compilation symbols, but make sure you set the project configuration to Release-mode before doing so, as these settings are per configuration.

所以基本上,除非您将其添加到文本框中,#if RELEASE 不会在任何配置下生成任何代码.

So basically, unless you add that to the text box, #if RELEASE won't produce any code under any configuration.

这篇关于#if RELEASE 会像 C# 中的 #if DEBUG 那样工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆