我有兩個共享兩個公共屬性Id和Information的類。將兩個類合併到使用LINQ的字典中
public class Foo
{
public Guid Id { get; set; }
public string Information { get; set; }
...
}
public class Bar
{
public Guid Id { get; set; }
public string Information { get; set; }
...
}
使用LINQ,我怎麼能採取的Foo對象填充的列表和酒吧對象填充的列表:
var list1 = new List<Foo>();
var list2 = new List<Bar>();
和合併 Id和各信息到一個單一的詞典:
var finalList = new Dictionary<Guid, string>();
在此先感謝您。
你想有,如果有發生什麼事做兩個具有相同ID但信息不同的項目? – 2012-07-25 17:46:09
@ErikPhilips這種可能性不會發生,所以它不是我需要處理的。 – Jonathan 2012-07-25 17:46:54
檢查這裏的解決方案:http://stackoverflow.com/questions/4038978/map-two-lists-into-a-dictionary-in-c-sharp – 2012-07-25 17:48:23