title: No result in LINQ query gives Object reference not set to an instance of an object in IF ELSE statement
body: <p>I have the following code:</p>
  
  <pre><code>        DataClasses1DataContext db = new DataClasses1DataContext();
  
          var UserInfo = db.Users.FirstOrDefault(u =&gt; u.Email == TextBox1.Text);
  
          if (UserInfo.Email != null)
          {
              Label2.Text = "Email is not null";
          }
          else
          {
              Label2.Text = "Email is null";
          }
  </code></pre>
  
  <p>If an e-mail address exists in the table, it successfully prints "Email is not null." However, if there is no matching record, I then receive an Object reference not set to an instance of an object error for Line 29:</p>
  
  <pre>
  Line 27:             DataClasses1DataContext db = new DataClasses1DataContext();
  Line 28: 
  Line 29:             var UserInfo = db.Users.FirstOrDefault(u => u.Email == TextBox1.Text);
  Line 30: 
  Line 31:             if (UserInfo.Email != null)
  </pre>
  
  <p>I'm stumped! Any help would be greatly appreciated.</p>