title: Test a variable's Existence
body: <p>I actually tried to check whether a <code>variable</code> defined in the program or not.
  I had done it by using the <code>exception handling</code> technique like below,</p>
  
  <pre><code>private sub IsTestVarDefined() as boolean
    try
     dim xDummy = AnObject.TestVar  'Where AnObject is using the type Object
     return true
    catch
     return false
    end try
  end sub
  </code></pre>
  
  <p>Is there any simple solutions available to achieve this.? or is this fine to implement.?</p>
  
  <p>If i am programming with javascript, then i would have done like this,</p>
  
  <pre><code>if(TypeOf Testvar === "undefined") { ... }
  </code></pre>
  
  <p>I have been searching for the methodology which is very similar to the above, in vb.net.</p>
  
  <p><strong>A sample picture of my case:</strong></p>
  
  <pre><code>Public Class Class1
   public Dim xVar as integer = 0
  End Class 
  
  Public Class Class2
   public Dim xAnotherVar as integer = 0
  End Class 
  
  Public Class SomeOtherClass
   Dim xObj as Object  = New Class2
   'Now i want to check whether the xObj is having xVar or Not?
  End Class 
  </code></pre>
  
  <p><em><strong>Additional Notes:</em></strong></p>
  
  <p>@Damien_The_Unbeliever solution returning Nothing eventhough the casted object having that member.</p>
  
  <pre><code>'Evaluated by using the above case i given
   ?xObj.GetType().GetProperty("xAnotherVar")
   Nothing
  </code></pre>