title: Check if a value is null before casting and assigning
body: <p>I'm using c# .net 2.0 and need to check if the value returned from my method that I am assigning my object to is null.</p>
  
  <p>My code is</p>
  
  <pre><code>MyObjectValue myObjectValue= (MyObjectValue) myObjectField.GetFieldValue();
  </code></pre>
  
  <p>In this instance the value returned by myObjectField.GetFieldValue() could be null and I want to check this before assigning to myObjectValue. At the moment it throws an exception object reference not set to a value of an object.</p>
  
  <p>The actual line of code is using the SharePoint API</p>
  
  <pre><code>SPFieldUserValue lawyerResponsibleFieldValue = 
      (SPFieldUserValue)lawyerResponsibleUserField.GetFieldValue(
                workflowProperties.Item[lawyerResponsibleUserField.Id].ToString());
  </code></pre>