【发布时间】:2010-04-13 21:01:30
【问题描述】:
为什么第一个 if 语句的计算结果为 true?我知道如果我使用“is”而不是“=”,那么它不会评估为真。如果我用“Foo”替换 String.Empty,它不会评估为真。 String.Empty 和 "Foo" 都具有相同类型的 String,那么为什么一个评估为 true 而另一个不评估呢?
//this evaluates to true
If Nothing = String.Empty Then
End If
//this evaluates to false
If Nothing = "Foo" Then
End If
【问题讨论】:
-
你是用
.Equals()的方法来比较的吗? -
我添加了一个代码sn-p。我实际上不需要在 null 和空字符串之间进行比较,我只是好奇为什么该语句评估为 true。
-
Nothing=String.Empty但String.Empty != Nothing。我刚刚发现了这个