我有以下代碼:如何比較兩個數組列表?
List<byte[]> list1 = new List<byte[]>();
list1.Add(new byte[] { 0x41, 0x41, 0x41, 0x41, 0x78, 0x56, 0x34, 0x12 });
List<byte[]> list2 = new List<byte[]>();
list2.Add(new byte[] { 0x41, 0x41, 0x41, 0x41, 0x78, 0x56, 0x34, 0x12 });
list2.Add(new byte[] { 0x42, 0x42, 0x42, 0x42, 0x78, 0x56, 0x34, 0x12 }); // this array
IEnumerable<byte[]> list3 = list2.Except(list1);
我想項目list3只包含字節[]數組是在list2中而不是在列表1(一個標有「本陣」),而是它只是返回所有的list2。所以然後我嘗試了以下內容:
List<byte[]> list3 = new List<byte[]>();
foreach (byte[] array in list2)
if (!list1.Contains(array))
list3.Add(array);
但是這給了我相同的結果。我究竟做錯了什麼?
我懷疑這會是這樣的排序是這樣,也沒有找到任何簡單地做它的路權,而無需通過每個陣列中的每個字節一個循環。非常感謝! – user1067239