Condividi tramite


Niente e stringhe in Visual Basic

Il runtime di Visual Basic e .NET Framework valutano Nothing in modo diverso quando si tratta di stringhe.

Visual Basic Runtime e .NET Framework

Si consideri l'esempio seguente:

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

Il runtime di Visual Basic in genere restituisce Nothing una stringa vuota (""). .NET Framework, tuttavia, non genera un'eccezione ogni volta che viene effettuato un tentativo di eseguire un'operazione di stringa su Nothing.

Vedere anche