Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Visual Basic runtime and the .NET Framework evaluate Nothing
differently when it comes to strings.
Visual Basic Runtime and the .NET Framework
Consider the following example:
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
The Visual Basic runtime usually evaluates Nothing
as an empty string (""). The .NET Framework does not, however, and throws an exception whenever an attempt is made to perform a string operation on Nothing
.
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.