Nothing 和字符串 (Visual Basic)
Visual Basic 运行时和 .NET Framework 在处理字符串时以不同的方式计算 Nothing。
Visual Basic 运行时与 .NET Framework
请看下面的示例:
Dim MyString As String = "This is my string"
Dim stringLength As Integer
' Explicitly set the string to Nothing.
MyString = Nothing
' stringLength = 0
stringLength = Len(MyString)
' This line, however, causes an exception to be thrown.
stringLength = MyString.Length
Visual Basic 运行时通常将 Nothing 作为空字符串 ("") 计算。 但是 .NET Framework 则不同,每当尝试对 Nothing 执行字符串操作时都将引发异常。