Share via


Nothing y cadenas en Visual Basic

El runtime de Visual Basic y el runtime de .NET Framework evalúan Nothing de manera diferente cuando afecta a las cadenas.

Visual Basic Runtime y .NET Framework

Considere el ejemplo siguiente:

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

El runtime de Visual Basic normalmente evalúa Nothing como una cadena vacía (""). Sin embargo, .NET Framework no lo hace, y se producirá una excepción cuando se intente realizar una operación de cadena en Nothing.

Vea también

Otros recursos

Introducción a las cadenas en Visual Basic