我有兩個數組,我需要顯示array1具有哪個array2,反之亦然。除了()給兩個數組輸出錯誤?
string[] a = { "hello", "momo" }
string[] b = { "hello"}
輸出:
momo
我現在用的。除,並試圖顯示一個消息框的輸出,但是當我執行我的代碼的輸出是這樣的:
System.Linq.Enumerable+<ExceptIterator>d_99'1[System.Char]
我的代碼:
//Array holding answers to test
string[] testAnswer = new string[20] { "B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A" };
string a = Convert.ToString(testAnswer);
//Reads text file line by line. Stores in array, each line of the file is an element in the array
string[] inputAnswer = System.IO.File.ReadAllLines(@"C:\Users\Momo\Desktop\UNI\Software tech\test.txt");
string b = Convert.ToString(inputAnswer);
//Local variables
int index = 0;
Boolean arraysequal = true;
if (testAnswer.Length != inputAnswer.Length)
{
arraysequal = false;
}
while (arraysequal && index < testAnswer.Length)
{
if (testAnswer[index] != inputAnswer[index])
{
arraysequal = false;
}
index++;
}
MessageBox.Show("" + a.Except(b));
您已經遇到'object.ToString()'實現,它只返回類型的全名。你從'除外'想要什麼?很多人都驚訝地發現它是基於設置的 - 所以像順序和重複的東西在輸出中沒有任何區別。 – devgeezer