title: C# Add Object To List
body: <p>I have created a new empty List of type <strong>User</strong> (<strong>User</strong> is an Entity in my EDM)</p>
  
  <pre><code>List&lt;User&gt; AvailableLocums = new List&lt;User&gt;();
  AvailableLocums = null;
  </code></pre>
  
  <p>I also have another List of type <strong>User</strong> which is populated with the results of a query</p>
  
  <pre><code>List&lt;User&gt; Locums = _shiftDateService.GetAvailableLocums(id, shiftDate.shiftDateID).ToList();
  </code></pre>
  
  <p>I then wish to loop around the <strong>Locums</strong> List, do some logic, and then add the User to my <strong>AvailableLocums</strong> List</p>
  
  <pre><code>foreach (var locum in Locums)
  {
     //Do some logic
  
     AvailableLocums.Add(locum);
  
  }
  </code></pre>
  
  <p>However, when I try to do this I get the following error</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>I then tried to amend my code and do the following</p>
  
  <pre><code>foreach (var locum in Locums)
  {
         //Do some logic
  
         User locumUser = new User();
         locumUser = locum;
  
         AvailableLocums.Add(locumUser);     
  }
  </code></pre>
  
  <p>But again I get the same error</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>Could someone please help me with this?</p>
  
  <p>Thanks.</p>