inq*_*one 6 c# linq union list
也许是深夜,但我在这里难倒.我正在尝试将具有相同属性的多个列表合并为一个.我认为LINQ的.UNION可以做到这一点,但我错了.这是我的一些列表的示例:
LIST1 (report names):
Date Name Title Product
02/01/13 Steve Hello World Report
02/05/13 Greg Howdy Report
LIST2 (song names):
Date Name Title Product
01/01/13 John Time Song
01/05/13 Bob Sorry Song
LIST3 (games names):
Date Name Title Product
12/01/12 Google Bike Race Game
12/05/12 Apple Temple Run Game
Run Code Online (Sandbox Code Playgroud)
我的课非常简单.这是它的样子:
public class MyClass {
public DateTime Date { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Product { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果您想知道,我使用此LINQ查询来获取上述列表之一:
var finalList = Games
.Select (s => new MyClass {
Date = (System.DateTime) s.Games.Creation_date,
Name = s.Games.Last_name,
Title = string.Format("{0} (Report)", s.Game.Headline),
Product="Report"
})
;
Run Code Online (Sandbox Code Playgroud)
到目前为止,它很简单,但我希望将所有列表合并为1.因此,我的最终列表应如下所示:
Date Name Title Product
02/01/13 Steve Hello World Report
02/05/13 Greg Howdy Report
01/01/13 John Time Song
01/05/13 Bob Sorry Song
12/01/12 Google Bike Race Game
12/05/12 Apple Temple Run Game
Run Code Online (Sandbox Code Playgroud)
我认为UNION命令会这样做:
var newList = List1.Union(List2).Union(List3);
Run Code Online (Sandbox Code Playgroud)
但我没有得到理想的输出.
Date Name Title Product
02/01/13 Steve Hello World Report
02/05/13 Greg Howdy Report
01/01/13 Bob Time Game
01/05/13 John Sorry Song
12/01/12 Google Bike Race Song
12/05/12 Apple Temple Run Game
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
man*_*lds 14
尝试:
list1.Concat(list2).Concat(list3);
Run Code Online (Sandbox Code Playgroud)
你不想使用Union(工作与否),因为它确实设置了联合.