I’m currently writing a simple app to compare two lists and return differences if any are found.
Note – [int] imaginary index for the purpose of this explanation
//---------------Prep----------------------------
ArrayList list1 = new ArrayList();
ArrayList storage = new ArrayList();
ArrayList list2 = new ArrayList();
string path = Application.ExecutablePath;
string root = Path.GetDirectoryName(path);
//---------------END Prep------------------------
//---------------Load content into list1------------------------
StreamReader objReader = new StreamReader(root + "/healthy.txt");
string sLine = "";
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
list1.Add(sLine);
}
objReader.Close();
//---------------END Load content into list1------------------------
//---------------Load content into list2------------------------
string[] files = Directory.GetFiles(root, "*.txt", SearchOption.AllDirectories);
foreach (string file in files)
{
storage.Add(file.ToString());
}
foreach (string sOutput2 in storage)
{
list2.Add(GetMD5HashFromFile(sOutput2));
}
//---------------END Load content into list2------------------------
I tried everything, but it seems that I cannot crack this.. How do I ”loop” through both lists and compare each item side by side in order then return the one’s in list two that do not match the control list(list one)?
Logically the program would return ”More work” as the wrong entry, because both “music” and “more work” are in the third row of their respective lists, they get checked and do not match. List 1 is control, so list 2’s entry gets recorded as the odd one out.
Now I have tried it right and left, but I cannot make it happen.. Anyone out there who would be willing to shed some light on this or perhaps even guide me through to the right answer?
Many thanks
EDIT: Added my code for both arrayLists, im only missing the comparison function…
No particular reason for using ArrayList, any suggestions that would make this process easier are very welcome.
For starters, let’s use a more modern way to read the lines:
And then the list of files from list2 that are not in list1 :