Is Vs = and nothing
-
Hello, Here is a verry easy example of my problem : Code : Dim d As Object = Nothing If d Is Nothing Then MsgBox("1") End If If d = Nothing Then MsgBox("2") End If If 0 = Nothing Then MsgBox("3") End If Show 1,2 and 3. what is the difference between "is" and "=" ? Nothing = 0 ? Thanks.
-
Hello, Here is a verry easy example of my problem : Code : Dim d As Object = Nothing If d Is Nothing Then MsgBox("1") End If If d = Nothing Then MsgBox("2") End If If 0 = Nothing Then MsgBox("3") End If Show 1,2 and 3. what is the difference between "is" and "=" ? Nothing = 0 ? Thanks.
You use 'Is' when checking for equality on reference types and '=' when checking for equality on value types. Not entirely sure why 'Is' and '=' works with Object but I'm guessing it's because Object could be either a reference type or a value type.
-
Hello, Here is a verry easy example of my problem : Code : Dim d As Object = Nothing If d Is Nothing Then MsgBox("1") End If If d = Nothing Then MsgBox("2") End If If 0 = Nothing Then MsgBox("3") End If Show 1,2 and 3. what is the difference between "is" and "=" ? Nothing = 0 ? Thanks.
I don't see any difference in the first two. 3rd one will always evaluate as TRUE and compiler may change the code like
If True Then
MsgBox("3")
End If:)
Navaneeth How to use google | Ask smart questions
-
Hello, Here is a verry easy example of my problem : Code : Dim d As Object = Nothing If d Is Nothing Then MsgBox("1") End If If d = Nothing Then MsgBox("2") End If If 0 = Nothing Then MsgBox("3") End If Show 1,2 and 3. what is the difference between "is" and "=" ? Nothing = 0 ? Thanks.
The "=" and "<>" operators test whether the operands refer to identical objects; the "Is" and "IsNot" operators test whether the operands refer to the same object. Note that many types objects do not support direct equality testing with the "=" and "<>" operators. I would advise against using "=" or "<>" with objects other than those with explicit support for such semantics (e.g. strings).
-
Hello, Here is a verry easy example of my problem : Code : Dim d As Object = Nothing If d Is Nothing Then MsgBox("1") End If If d = Nothing Then MsgBox("2") End If If 0 = Nothing Then MsgBox("3") End If Show 1,2 and 3. what is the difference between "is" and "=" ? Nothing = 0 ? Thanks.