1 /// <summary>
2 /// 字节数组比较
3 /// </summary>
4 /// <param name="bytearray1">字节数组 1</param>
5 /// <param name="bytearray2">字节数组 2</param>
6 /// <returns>如果两个数组相同,返回0;如果数组1大于数组2,返回负值;反之,则返回值大于0。</returns>
7 public int MemoryCompareByteArray(byte[] bytearray1, byte[] bytearray2)
8 {
9 int result = 0;
10 if (bytearray1.Length != bytearray2.Length)
11 {
12 result = bytearray1.Length - bytearray2.Length;
13 }
14 else
15 {
16 for (int i = 0; i < bytearray1.Length; i++)
17 {
18 if (bytearray1[i] != bytearray2[i])
19 {
20 result = (int)(bytearray1[i] - bytearray2[i]);
21 break;
22 }
23 }
24 }
25 return result;
26 }