title: Checking if an object is null in C#
body: <p>I would like to prevent further processing on an object if it is null.</p>
  
  <p>In the following code I check if the object is null by either:</p>
  
  <pre><code>if (!data.Equals(null))
  </code></pre>
  
  <p>and</p>
  
  <pre><code>if (data != null)
  </code></pre>
  
  <p>However, I receive a <code>NullReferenceException</code> at <code>dataList.Add(data)</code>. If the object was null, it should never have even entered the <code>if</code>-statement!</p>
  
  <p>Thus, I'm asking if this is proper way of checking if an object is null:</p>
  
  <pre><code>public List&lt;Object&gt; dataList;
  public  bool AddData(ref Object data)
      bool success = false;
      try
      {
          // I've also used "if (data != null)" which hasn't worked either
          if (!data.Equals(null))
          {
             //NullReferenceException occurs here ...
             dataList.Add(data);
             success = doOtherStuff(data);
          }
      }
      catch (Exception e)
      {
          throw new Exception(e.ToString());
      }
      return success;
  }
  </code></pre>
  
  <p>If this is the proper way of checking if the object is null, what am I doing wrong (how can I prevent further processing on the object to avoid the NullReferenceException)?</p>