in VB is there any situation whereby x = Nothing
is not the same as x is Nothing
?
Also, x <> Nothing
vs x IsNot Nothing
I'm thinking that they are purely identical.. but just wanted to be sure.
<> in VB.NET means "not equal to". It can be used with the normal oprands as well as in comparision with the items when compared with the datas fetched with the data reader (from database). Follow this answer to receive notifications.
IsNothing is intended to work on reference types. It returns True if the expression represents an object variable that currently has no object assigned to it; otherwise, it returns False.
For non-nullable value types, Nothing in Visual Basic differs from null in C#. In Visual Basic, if you set a variable of a non-nullable value type to Nothing , the variable is set to the default value for its declared type.
The Nothing keyword is used to disassociate an object variable from an actual object. Use the Set statement to assign Nothing to an object variable. For example: VB Copy. Set MyObject = Nothing.
There's a difference with empty strings, which do count as Nothing with simply "=" or "<>" but don't count as Nothing for Is / IsNot:
Public Class Test
Public Shared Sub Main()
Dim x As String = ""
Console.WriteLine(x = Nothing) ' True
Console.WriteLine(x Is Nothing) ' False
End Sub
End Class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With