「VB.NET」IsNothing関数で変数Null判定をする
書式
If 変数名 Is nOthing Then
処理コード1
Else
処理コード2
End If
使用例
Module Module1
Public Sub Main()
'変数定義
Dim strA = Nothing
Dim strB = "google"
'Nothing判定
If strA Is Nothing Then
Console.WriteLine("変数名strAはNothingです。")
Else
Console.WriteLine("変数名strAはNothingではありません。")
End If
'Nothing判定
If strB Is Nothing Then
Console.WriteLine("変数名strBはNothingです。")
Else
Console.WriteLine("変数名strBはNothingではありません。")
End If
Console.ReadKey()
End Sub
End Module
実行結果
変数名strAはNothingです。
変数名strBはNothingではありません。