我正在研究一个让我的大脑融化的问题,尽管我认为它不应该这么难。我的例子很长,所以我会尽量让我的问题简短!
我有一个数组对象,其中包含一些也是数组的元素。例如:
customerAddresses = new customer_address[]
{
new // address #1
{
customer_id = 6676979,
customer_address_seq = 1,
customer_address_match_codes = new []
{
new
{
customer_address_seq = 1,
customer_id = 6676979,
customer_match_code_id = 5
}
}
},
new // address #2
{
customer_id = 6677070,
customer_address_seq = 1,
customer_address_match_codes = new []
{
new
{
customer_address_seq = 1,
customer_id = 6677070,
customer_match_code_id = 4
},
new
{
customer_address_seq = 1,
customer_id = 6677070,
customer_match_code_id = 5
},
new
{
customer_address_seq = 1,
customer_id = 6677070,
customer_match_code_id = 3
}
}
},
new // address #3
{
customer_id = 6677070,
customer_address_seq = 2,
customer_address_match_code = new []
{
new
{
customer_address_seq = 2,
customer_id = 6677070,
customer_match_code_id = 4
},
new
{
customer_address_seq = 2,
customer_id = 6677070,
customer_match_code_id = 5
}
}
}
};
如您所见,数组包含许多地址记录,每个customer_id
和的组合都有一条记录customer_address_seq
。我要做的是customer_address
根据以下规则找到最佳匹配:
- 必须
customer_match_code_id
等于 4 并且必须有 1 等于 5 - 如果有一个
customer_match_code_id
等于 3,则认为这是customer_address
一个更强的匹配。
根据上述规则,第二个customer_address
元素是“最佳匹配”。然而,这个问题的最后一点复杂性是可能有多个“最佳匹配”。我需要如何处理这种情况是通过customer_address
记录 minimumcustomer_id
和 minimum customer_address_seq
。
我在想使用 LINQ 将是我最好的选择,但我对它的经验不够,所以我只是不停地旋转我的轮子。