1.引用:using System.IO;算法
2.代碼:數組
class Program
{
static void Main(string[] args)
{
string filePath1 = "F:\\測試文件\\11.txt";
string filePath2 = "F:\\測試文件\\22.txt";
using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file1 = new FileStream(filePath1, FileMode.Open), file2 = new FileStream(filePath2, FileMode.Open))
{
byte[] hashByte1 = hash.ComputeHash(file1);//哈希算法根據文本獲得哈希碼的字節數組
byte[] hashByte2 = hash.ComputeHash(file2);
string str1 = BitConverter.ToString(hashByte1);//將字節數組裝換爲字符串
string str2 = BitConverter.ToString(hashByte2);
if (str1 == str2)
{測試
Console.WriteLine("相同");字符串
}
else
{string
Console.WriteLine("不一樣");hash
}
}
Console.ReadKey();
}
}
}it