Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Is Vs = and nothing

Is Vs = and nothing

Scheduled Pinned Locked Moved Visual Basic
questionvisual-studiohelptutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thesum
    wrote on last edited by
    #1

    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.

    J N S K 4 Replies Last reply
    0
    • T thesum

      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.

      J Offline
      J Offline
      Jay Royall
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T thesum

        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.

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • T thesum

          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.

          S Offline
          S Offline
          supercat9
          wrote on last edited by
          #4

          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).

          1 Reply Last reply
          0
          • T thesum

            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.

            K Offline
            K Offline
            kvelu d
            wrote on last edited by
            #5

            "=" represents the string values "is" represents the object type values

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups