Partager via


Nothing et les chaînes en Visual Basic

Mise à jour : novembre 2007

Le runtime Visual Basic et le .NET Framework évaluent Nothing différemment lorsqu'il s'agit de chaînes.

Runtime Visual Basic et le .NET Framework

Prenons l'exemple suivant :

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

Le runtime Visual Basic évalue habituellement Nothing comme une chaîne vide (""). Ce n'est pas le cas du .NET Framework qui lève une exception lors d'une tentative d'exécution d'une opération de chaîne sur Nothing.

Voir aussi

Autres ressources

Introduction aux chaînes en Visual Basic