2016-04-21 83 views
2

我有2層結構:需要通過鍵和值在C#中相交2個字典

public struct Customer 
{ 
    public string Code { get; set; } 
    public string Name { get; set; } 
    public string Address { get; set; } 
} 

public class OrganizationDto 
{ 
    public int OrgId { get; set; } 
    public string Name { get; set; } 
    public int PeopleCount { get; set; } 
    public string CCEmail { get; set; } 
    public string address { get; set; } 
} 

而且2字典:

Dictionary<string, Customer> dataCustomer = new Dictionary<string, Customer>(); 
Dictionary<string, OrganizationDto> dataOrganization = new Dictionary<string, OrganizationDto>(); 

我該如何映射2乘:
鍵和不同地址。所以我需要具有相同密鑰但具有不同地址的項目。
我想:

Dictionary<string, OrganizationDto> changed = dataOrganization 
      .Where(item => dataCustomer .Keys.Contains(item.Key)) 
      .ToDictionary(item => item.Key, item => item.Value); 

這讓我通過關鍵的路口,但我不;知道如何選擇只與不同的地址(當然公共密鑰)的人。

感謝

回答

2

過濾

var changed = dataOrganization 
     .Where(item => dataCustomer.Keys.Contains(item.Key) 
         && item.Address != dataCustomer[item.Key].Address) 
     .ToDictionary(item => item.Key, item => item.Value); 
時比較地址屬性