我目前正在編寫一個簡單的應用程序來比較兩個列表並返回差異,如果有任何發現。兩個ArrayLists中的項目比較和返回差異
注 - [INT]對於這種解釋
//---------------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------------------------
我都試過了,但似乎我不能破解這個目的虛指標..我如何「通過這兩個列表」循環'和並排比較每個項目,然後返回列表2中與控制列表(列表1)不匹配的項目?
邏輯上,程序會返回''更多作品''作爲錯誤的條目,因爲「音樂」和「更多作品」都位於各自列表的第三行,因此它們會被檢查並且不匹配。列表1是控件,因此列表2的條目被記錄爲奇數列。
現在我已經嘗試了它的權利和離開,但我不能讓它發生..任何人誰會願意在這一點上,或者甚至指導我通過正確的答案嗎?
非常感謝
編輯:添加我的代碼兩者的ArrayList,我只是缺少比較功能...
使用ArrayList的,有什麼建議沒有特別的原因,這將使這個過程變得更容易是非常歡迎。
爲什麼使用ArrayList?你還在使用Fx 1.x嗎?你可以使用LINQ嗎?例如,請添加更多像真實代碼一樣的東西。 Docs是一個數組嗎?請注意,您有一個_edit_按鈕。 –
你有什麼特別的理由使用ArrayList? – asawyer
列表是否已排序?給定列表「{1,2,4}」和「{1,2,3,4}」,結果應該是「3」嗎?如果列表沒有排序,是否認爲'{1,2,3}'與'{3,2,1}'相同? –