是否有 C# 的 VB.net 等价物!操作员? [英] Is there a VB.net equivalent for C#'s ! operator?
问题描述
在使用 C# 两年后,由于我目前的工作,我现在又回到了 VB.net.在 C# 中,我可以对字符串变量上的 null 或 false 值进行简短的测试,如下所示:
After two years of C#, I'm now back to VB.net because of my current job. In C#, I can do a short hand testing for null or false value on a string variable like this:
if(!String.IsNullOrEmpty(blah))
{
...code goes here
}
但是我对如何在 VB.net 中执行此操作感到有些困惑.
however I'm a little confused about how to do this in VB.net.
if Not String.IsNullOrEmpty(blah) then
...code goes here
end if
以上语句是否表示字符串不为空或不为空?Not
关键字是否像 C# 的 !
运算符一样操作?
Does the above statement mean if the string is not null or empty? Is the Not
keyword operate like the C#'s !
operator?
推荐答案
在您展示的上下文中,VB Not
关键字确实等效于 C# !
运算符.但请注意,VB Not
关键字实际上已重载以表示两个 C# 等效项:
In the context you show, the VB Not
keyword is indeed the equivalent of the C# !
operator. But note that the VB Not
keyword is actually overloaded to represent two C# equivalents:
- 逻辑否定:
!
- 按位补码:
~
例如,下面两行是等价的:
For example, the following two lines are equivalent:
- C#:
useThis &= ~doNotUse;
- VB:
useThis = useThis And (Not doNotUse)
这篇关于是否有 C# 的 VB.net 等价物!操作员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!