小编use*_*239的帖子

如何比较两个数组列表?

我有以下代码:

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);
Run Code Online (Sandbox Code Playgroud)

我希望list3只包含list2中但不在list1中的byte []数组(标记为"this array"的数组),而是只返回list2的全部内容.那么我尝试了以下内容:

List<byte[]> list3 = new List<byte[]>();
foreach (byte[] array in list2)
    if (!list1.Contains(array))
        list3.Add(array);
Run Code Online (Sandbox Code Playgroud)

但这让我得到了同样的结果.我究竟做错了什么?

c# arrays byte list

4
推荐指数
1
解决办法
1426
查看次数

标签 统计

arrays ×1

byte ×1

c# ×1

list ×1