本文介绍了单行If语句问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下单行if语句,即使它不应该评估为真,即使它是b $ b。我以前从未见过这个,我担心这会在我的代码的其他区域发生这种情况。


如果String1.Length> 0然后String2 = String1


其中String1 =""


当String1 =""时,此语句的计算结果为true:


如果String1<> ""然后String2 = String1


将If语句更改为多行If语句更正问题:


如果String1.Length> 0然后

String2 = String1

结束如果


有没有其他人看到这个问题或知道发生了什么?


谢谢

解决方案




I have the following single-line if statement that is evaluating true even
though it shouldn''t. I have never seen this before and I am concerned that
this can happen in other areas of my code.

If String1.Length > 0 Then String2 = String1

where String1 = ""

This statement also evaluates as true when String1 = "":

If String1 <> "" Then String2 = String1

Changing the If statement to a multi-line If statement corrects the problem:

If String1.Length > 0 Then
String2 = String1
End If

Has anyone else seen this problem or know what''s going on?

Thanks

解决方案







这篇关于单行If语句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 06:41