Nothing and Strings in Visual Basic
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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for