通過System.Security.Cryptography.HashAlgorithm 哈希算法獲取文件的哈希值比較判斷
public static bool CompareFile(string filePath1, string filePath2) { //計算第一個文件的哈希值 HashAlgorithm hash = HashAlgorithm.Create(); var stream_1 = new System.IO.FileStream(filePath1, System.IO.FileMode.Open); byte[] hashByte_1 = hash.ComputeHash(stream_1); stream_1.Close(); //計算第二個文件的哈希值 var stream_2 = new System.IO.FileStream(filePath2, System.IO.FileMode.Open); byte[] hashByte_2 = hash.ComputeHash(stream_2); stream_2.Close(); return BitConverter.ToString(hashByte_1) == BitConverter.ToString(hashByte_2); }