我有一个方法,我目前正在构建比较两个对象列表。该清单自身包含对象如何将一组对象和结果从一个方法返回
List<TradeFile> list1
List<TradeFile> list2
当我完成从列表1和TradeFile对象从列表2比较TradeFile对象,我想返回一个包含所有比较TradeFiles和匹配状态的集合。因此,这将是这样的:
TradeFile1,TradeFile2,真 TradeFile1,TradeFile2,假
我会用这个集合,然后供以后在我的过程报告。我应该看看使用包含交易文件对象集合的字典吗?
这可以工作,但真的感觉凌乱:
Dictonary<Dictonary<TradeFile,TradeFile>,bool>
编辑: 这是它结束了基于一些下面的答案看起来像。
private List CompareTradeFileObject(List list1,List list2) { List results = new List(); bool matches = false;
if (list1.Count == list2.Count)
{
list1.Sort((x, y) => x.FormatName.CompareTo(y.FormatName));
list2.Sort((x, y) => x.FormatName.CompareTo(y.FormatName));
for (int i = 0; i < list1.Count; i++)
{
TradeFileCompare tf = new TradeFileCompare();
tf.TradeFile1 = list1[i];
tf.TradeFile2 = list2[i];
if (list1[i].FileExtension == list2[i].FileExtension && list1[i].FormatName == list2[i].FormatName &&
list1[i].GroupName == list2[i].GroupName && list1[i].MasterAccountId == list2[i].MasterAccountId)
{
matches = CompareTradeFileContents(list1[i].FileContents, list2[i].FileContents);
tf.IsMatch = matches;
}
else
{
tf.IsMatch = matches;
}
results.Add(tf);
}
}
else
{
matches = false;
}
return results;
}
class TradeFileCompare
{
public TradeFile TradeFile1 { get; set; }
public TradeFile TradeFile2 { get; set; }
public bool IsMatch { get; set; }
}