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 }