If the contents of the file are identical, then the cryptographic hash will at least give a very good idea of ββequality. The class SHA256would be a good candidate here, although it may be just above the top. For instance:
static byte[] Sha256HashFile(string file)
{
using (SHA256 sha256 = SHA256.Create())
{
using (Stream input = File.OpenRead(file))
{
return sha256.ComputeHash(input);
}
}
}
- , , Convert.ToBase64, . , :) Enumerable.SequenceEqual:
byte[] hash1 = Sha256HashFile("file1.png");
byte[] hash2 = Sha256HashFile("file2.png");
bool same = hash1.SequenceEqual(hash2);
, IEqualityComparer<byte[]>, , , base64. , :
var hashToNameMap = new Dictionary<string, string>();
foreach (string file in files)
{
byte[] hash = Sha256HashFile(file);
string base64 = Convert.ToBase64(hash);
string existingName;
if (hashToNameMap.TryGetValue(base64, out existingName))
{
Console.WriteLine("{0} is a duplicate of {1}", file, existingName);
}
else
{
hashToNameMap[base64] = file;
}
}
:
- , , .
- - (, , ). .
- , , ... , , , .
, , , .. , - , , , , , , .