如何比较字节两个阵列 [英] How to compare two arrays of bytes
本文介绍了如何比较字节两个阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有完全相同的内容两个字节数组。我想:
I have two byte arrays with the exact same content. I tried:
if (bytearray1 == bytearray2) {...} else {...}
和
if (Array.Equals(bytearray1, bytearray2)) {....} else {...}
所有时间它会转到别的!我不知道为什么!我手工检查两个数组几倍!!!
All time it goes to the else! I don't know why! I checked both arrays manually several times!!!
推荐答案
尝试使用的 SequenceEqual
扩展方法。例如:
Try using the SequenceEqual
extension method. For example:
byte[] a1 = new byte[] { 1, 2, 3 };
byte[] a2 = new byte[] { 1, 2, 3 };
bool areEqual = a1.SequenceEqual(a2); // true
这篇关于如何比较字节两个阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文