asp.net - Lambda expression C# Union Where -


i have objects of class

public class person     {         public string error { get; set; }         public string name { get; set; }         public int age { get; set; }     } 

some have error (and no name , age) have no error (and name , age)

person[] p1 = new person[] { new person { error = "error1" }, new person { name = "name1", age = 1 } };    person[] p2 = p1                 .where(c => string.isnullorempty(c.error))                 .select(                     c => new person { name = c.name, age = c.age }                  ).toarray()                  union()                 .where(d => !string.isnullorempty(d.error))                 .select(                     d => new person { error = d.error }                  ).toarray() 

i need create second array p2, can select persons objects p1 have error, , union persons same p1 have no error.

i need in code above, it's not working. how can write in 1 lambda clause?

thanks lot?

p1.where(c => string.isnullorempty(c.error))                  .union(p1.where(d => !string.isnullorempty(d.error)))                 .toarray() 

you need add second ienumberable inside .union. , no need project again since objects type need.

although it's kind of moot in case, result same p1


Comments