字節數組比較大小


 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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM