如何使用#IF DEBUG在VB.NET [英] How to use #IF DEBUG in VB.NET
问题描述
是否有可能从内部分配一个值的一类变量 #IF DEBUG
的条件?
Is it possible to assign a value to a class variable from inside a #IF DEBUG
conditional?
我想从里面我主要形式的负载,如果我在正在运行有条件地执行一些code DEBUG
模式。我想我可以做这样的事情:
I want to conditionally execute some code from inside my main form load if I am running in DEBUG
mode. I thought I could do something like:
Public Class Form1
public DEB as Integer
#if DEBUG then
DEB = 1
#else
DEB = 0
#end if
Private Sub Form1_Load(....)
if DEB=1 Then
<do something>
else
<do something else>
end if
....
不过,好像你不能赋值给一个变量。我显然不理解的范围界定正确。我似乎无法把#如果DEBUG
荷载子例程中。如何做到这一点?
However, it seems like you can't assign a value to a variable. I'm obviously not understanding the scoping correctly. I can't seem to put the #if DEBUG
inside the Load sub routine. How do I do this?
推荐答案
为什么不直接测试的编译常量?您还没有通过测试的实际变量得到什么。
Why not just test the compilation constant directly? You are not gaining anything by testing an actual variable.
Public Class Form1
Private Sub Form1_Load(....)
#if DEBUG then
<do something>
#else
<do something else>
#end if
End Sub
End Class
这篇关于如何使用#IF DEBUG在VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!