What is the difference between 'foo = Nothing' and 'foo is Nothing' in VB.NET?

后端 未结 6 773
醉梦人生
醉梦人生 2021-01-02 07:12

In VB.NET, what is the difference between

if foo is Nothing Then
      doStuff()
End If

and

if foo=Nothing Then
    doStuff         


        
6条回答
  •  执笔经年
    2021-01-02 07:35

    foo is Nothing simply checks if `foo` is not assigned to any reference.
    
    foo=Nothing checks if the reference held by `foo` is equal to `nothing`
    

    In VB, both statements will evaluate to the same value if foo has not been initialised

提交回复
热议问题