VB.NET 中的 And 和 AndAlso 有什么区别? [英] What is the difference between And and AndAlso in VB.NET?

查看:50
本文介绍了VB.NET 中的 And 和 AndAlso 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB.NET中,AndAndAlso有什么区别?我应该使用哪个?

In VB.NET, what is the difference between And and AndAlso? Which should I use?

推荐答案

And 运算符计算两边,其中 AndAlso 计算右边当且仅当左边一边是真的.

The And operator evaluates both sides, where AndAlso evaluates the right side if and only if the left side is true.

示例:

If mystring IsNot Nothing And mystring.Contains("Foo") Then
  ' bla bla
End If

如果mystring = Nothing

If mystring IsNot Nothing AndAlso mystring.Contains("Foo") Then
  ' bla bla
End If

这个不会抛出异常.

因此,如果您来自 C# 世界,您应该像使用 && 一样使用 AndAlso.

So if you come from the C# world, you should use AndAlso like you would use &&.

更多信息在这里:http:///www.panopticoncentral.net/2003/08/18/the-ballad-of-andalso-and-orelse/

这篇关于VB.NET 中的 And 和 AndAlso 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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