2012-07-26 118 views
1

我有兩個sortedlists排序列表比較

1. oldlist<int,int> 

2. newlist <int,int> 

(應用程序特定的信息 - 關鍵是industryId和值重)

我想比較列表中的變化。

我想下面的東西 -

  • 項目的列表,其中重量是不爲零,但其在newlist爲零。

  • 重量不爲零且已從舊列表更改的項目列表。

我知道有一種叫做比較器的東西。 可以在這裏使用嗎?

回答

3

您可以使用LINQ:

// list of items where weight was not zero, but its zero in the newlist. 
var result1 = from o in oldList 
       join n in newList on o.Key equals n.Key 
       where o.Value != 0 && n.Value == 0 
       select new {Old = o, New = n}; 

// list of items where weight is not zero and has changed from oldlist. 
var result2 = from o in oldList 
       join n in newList on o.Key equals n.Key 
       where o.Value != 0 && o.Value != n.Value 
       select new { Old = o, New = n };