There are several ways to do this, each with its advantages. As there are no restrictions I will put what is probably the simplest way. I’m using LINQ:
var arquivo1 = File.ReadAllBytes(nomeArquivo1);
var arquivo2 = File.ReadAllBytes(nomeArquivo2);
WriteLine(arquivo1.SequenceEqual(arquivo2)); //mostra se é igual ou não
I put in the Github for future reference.
Some improvements can be made, such as loading the file on demand. Without loading byte per byte, which would be too slow, the ideal is to have a buffer of at least 4096 bytes.
When mounting the array, instead of using a array of bytes, could mount the bytes in sets of 8 and store in a array of Int64
and compare it. The comparison will be faster, but do not know how much the algorithm as a whole would be faster, have to consider the expense with the cast, the logic to assemble this, the load of data that would have to be a little different. Just testing to make sure which one would be faster.
If performance is very important maybe the use of pointers can help. As well as avoid the LINQ that has a small overhead. Again, just testing to be sure.
Some extra checks can be done if needed.
To make a difference between them is much more complicated and it is difficult to make right. Google has already made one diff before using known algorithms. It has a few tricks since it is a port.
There are other questions here that show how to scan a directory, just adapt to the desired algorithm:
What have you done? What is your specific question?
– Maniero
Maybe Winmerge or file comparison software will help you.
– David