我有以下代码:如何比较两个数组列表?
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