我想創建一個新的,刪除的,公共項目的分組列表。我目前這樣做:有沒有更有效的方法來創建一個分組列表
public class ListSortingGroupingTest
{
List<int> OldList = new List<int> { 1, 2, 3, 4, 5 };
List<int> NewList = new List<int> { 3, 4, 5, 7, 8, 9 };
public void CreateGroupedList()
{
var deleted = OldList.Except(NewList).Select(i => new { Group = "Deleted", Number = i });
var added = NewList.Except(OldList).Select(i => new { Group = "Added", Number = i});
var common = NewList.Intersect(OldList).Select(i => new { Group = "Common", Number = i});
var result = deleted.Union(added).Union(common);
}
}
This works。但我想知道是否有更好或更有效的方法?
最終我希望在WPF分組列表視圖中綁定到此。
夢幻般的答案和證明更有效。我用我的和你的實現跑秒錶,結果如下:ME =>執行時間:16954(6ms) YOU =>執行時間:1321(0ms) – John