title: Add List Element Based on Conditional with Linq Expression
body: <p>I have this very simple Linq query (the .Dump() function is being used with LinqPad in order to view the results):</p>
  
  <pre><code>void Main()
  {
      var myList = new List&lt;string&gt;
      {
          "One", "Two", "Three"
      };
  
  
      var result = from o in myList
      select o;
  
      result.Dump();
  }
  </code></pre>
  
  <p>How can I inject an if statement into the Linq query that populates <code>result</code> so that it checks to see if "Four" is in the list--and if it is not, then add it? I realize that there are ways to do this by looking at result after Linq has populated <code>result</code>, but I would like to add this logic into a single Linq query.</p>
  
  <p>Thank you.</p>
  
  <p>EDIT/CLARIFICATION: The "if" logic needs to be inside the Linq query. Here is the skeletal code:</p>
  
  <pre><code> var result = from o in myList
      select o
      [now add "four" if and only if it is not in the result]
      [now end the query and ensure `result` contains "one", "two", "three", and "four"];
  </code></pre>
  
  <p>SECOND EDIT:
  I am trying to query and add to the list in a single operation. By the way, I made this very simple example instead of giving the much more complex scenario I'm trying to handle, by the way, so it's not as if I am struggling with how to add a new element to a List object. :) </p>
  
  <p>So here is what I was going to do:</p>
  
  <p>// query the list to see if "four" is in the list
  (a Linq query goes here to check for "four")</p>
  
  <p>// if the result of the above is false then add "four" to the myArray List
  (add the new array element here)</p>
  
  <p>Instead, I would like to do the following:</p>
  
  <p>// query the list for its contents and also add "four" if it is not in the list.
  // all this needs to be done in a single "select" using Linq</p>
  
  <p>Is this not possible?</p>
  
  <p>Thank you.</p>