title: Problematic behavior of Linq Union?
body: <p>consider the following example:</p>
  
  <pre><code>    public IEnumerable&lt;String&gt; Test ()
      {
          IEnumerable&lt;String&gt; lexicalStrings = new List&lt;String&gt; { "test", "t" };
          IEnumerable&lt;String&gt; allLexicals = new List&lt;String&gt; { "test", "Test", "T", "t" };
  
          IEnumerable&lt;String&gt; lexicals = new List&lt;String&gt; ();
          foreach (String s in lexicalStrings)
              lexicals = lexicals.Union (allLexicals.Where (lexical =&gt; lexical == s));
  
          return lexicals;
      }
  </code></pre>
  
  <p>I'd hoped for it to produce "test", "t" as output, but it does not (The output is only "t"). I'm not sure, but may have to do something with the deferred processing. Any ideas how to get this to work or for a good alternative?</p>
  
  <p>Edit: Please note that this is just a simplified example. <code>lexicalStrings</code> and <code>allLexicals</code> are different types in the original code. So I cannot directly combine these.</p>
  
  <p>Edit2 the problem to solve looks more like this:</p>
  
  <pre><code>    public IEnumerable&lt;Lexical&gt; Test ()
      {
          IEnumerable&lt;String&gt; lexicalStrings = new List&lt;String&gt; { "test", "t" };
          IEnumerable&lt;Lexical&gt; allLexicals = new List&lt;Lexical&gt; { ... };
  
          IEnumerable&lt;Lexical&gt; lexicals = new List&lt;Lexical&gt; ();
          foreach (String s in lexicalStrings)
              lexicals = lexicals.Union (allLexicals.Where (lexical =&gt; lexical.Text == s));
  
          return lexicals;
      }
  </code></pre>