Loading

What is difference between And and Andalso in VB.net ?

The 'And' operator evaluate both side, where 'AndAlso' only evaluate the right side if the left side is true. An example:

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

This throws an exception if mystring = Nothing

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

This don't.
So if you come from the C# world, you should use AndAlso which is more like &&.

posted @ 2011-04-10 10:04  .net's  阅读(617)  评论(0编辑  收藏  举报