Nothing 和字符串 (Visual Basic)
更新:2007 年 11 月
当遇到字符串时,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 执行字符串操作时都将引发异常。