Partager via


Nothing et les chaînes en Visual Basic

Le runtime Visual Basic et .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 (""). Toutefois, ce n'est pas le cas du .NET Framework qui lève une exception à chaque tentative d'exécuter une opération de chaîne sur Nothing.

Voir aussi

Autres ressources

Introduction aux chaînes en Visual Basic