2016-04-21 43 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); 
时比较地址属性