title: How to check if cookies are empty or not
body: <p>I need to check if cookie is present with value or not. But I wonder if there is some quick and good way of doing so since if I need to check 3 cookies it seems bad to check with <code>if</code> or <code>try</code>.</p>
  
  <p>Why it does not assign empty string to my variable if cookie is not present? Instead it shows <code>Object reference not set to an instance of an object.</code></p>
  
  <p>My code (it works, but it seems too big for this task, I think there should be a better way of doing this)</p>
  
  <pre><code>// First I need to asign empty variables and I don't like this
  string randomHash = string.Empty;
  string browserHash = string.Empty;
  int userID = 0;
  
  // Second I need to add this huge block of try/catch just to get cookies
  // It's fine since I need all three values in this example so if one fails all fails
  try
  {
      randomHash = Convert.ToString(Request.Cookies["randomHash"].Value);
      browserHash = Convert.ToString(Request.Cookies["browserHash"].Value);
      userID = Convert.ToInt32(Request.Cookies["userID"].Value);
  }
  catch
  {
      // And of course there is nothing to catch here
  }
  </code></pre>
  
  <p>As you can see I have this huge block just to get cookies. What I would like is something like this:</p>
  
  <pre><code>// Gives value on success, null on cookie that is not found
  string randomHash = Convert.ToString(Request.Cookies["randomHash"].Value);
  string browserHash = Convert.ToString(Request.Cookies["browserHash"].Value);
  int userID = Convert.ToInt32(Request.Cookies["userID"].Value);
  </code></pre>
  
  <p>Edit
  Maybe I can somehow override the <code>.Value</code> method to my liking?</p>