I have a method that I am currently building to compare two lists of objects. The lists themselves contain objects
List<TradeFile> list1
List<TradeFile> list2
When I finish comparing TradeFile object from list1 and TradeFile object from list2, I want to return a collection that contains all of the compared TradeFiles and the matching status. So it would be something like:
TradeFile1, TradeFile2, True
TradeFile1, TradeFile2, False
I will use this collection then for reporting later in my process. Should I look at using something like a dictionary that contains a collection of the tradefile objects?
This may work, but really feels messy:
Dictonary<Dictonary<TradeFile,TradeFile>,bool>
Edit:
This is what it ended up looking like based on some the answer below.
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; }
}
Output: