title: Lambda expression C# Union Where
body: <p>I have objects of class</p>
  
  <pre><code>public class Person
      {
          public string Error { get; set; }
          public string Name { get; set; }
          public int Age { get; set; }
      }
  </code></pre>
  
  <p>some have Error (and no Name and Age) some have no Error (and Name and Age)</p>
  
  <pre><code>Person[] p1 = new Person[] { new Person { Error = "Error1" }, new Person { Name = "Name1", Age = 1 } };
  
  
  
  Person[] p2 = p1
                  .Where(c =&gt; string.IsNullOrEmpty(c.Error))
                  .Select(
                      c =&gt; new Person { Name = c.Name, Age = c.Age }
                   ).ToArray()
                   Union()
                  .Where(d =&gt; !string.IsNullOrEmpty(d.Error))
                  .Select(
                      d =&gt; new Person { Error = d.Error }
                   ).ToArray()
  </code></pre>
  
  <p>I need create second array p2, where I can select all persons objects from p1 which have Error, and Union all persons from same p1 which have no Error.</p>
  
  <p>I need something like in code above, but it's not working. How can I write it in one lambda clause?</p>
  
  <p>Thanks a lot?</p>