And と AndAlso
String[] array = new String[]{"item0", "item1", "item2"};
if(array.Length > 3 && array[3].Contains("item")){
Console.WriteLine("TRUE!!");
}
て書くように,なーんも考えずにVBで下のように書くと例外(ArrayIndexOutOfBoundsException)が発生する.
Dim array As String() = {"item0", "item1", "item2"}
If array.Length > 3 And array(3).Contains("item") Then
Console.WriteLine("TRUE!!")
End If
C#やJavaで言うところの「&&」はVBでは「AndAlso」なのでした.
C#,Java | VB |
---|---|
& | And |
&& | AndAlso |
| | Or |
|| | OrElse |