JDeats said:
Really, well it may not be the most optimal approach, but I tested it
multiple times before posting and it seemed to do the trick, I
wouldn't have posted something that didn't work.
I'm afraid you did though. Try this:
using System;
using System.Text;
class Test
{
static void Main()
{
byte[] b1 = {0x20};
byte[] b2 = {0xa0};
String s1 = Encoding.ASCII.GetString (b1);
String s2 = Encoding.ASCII.GetString (b2);
Console.WriteLine (s1==s2);
}
}
It prints "True" because the ASCII encoding truncates the top bit of
each byte. I'm sure your version would always correctly pick up byte
arrays which are equal, but it wouldn't always correctly pick up byte
arrays which *aren't* equal.
The two long strings will be picked up by the garbage collector, so it
should be do problem, but avoiding their creation would be more
efficient.
They would be picked up by the garbage collector, yes, but if the
images are of significant size the strings will be quite large (double
the size of whatever size the byte array is)
I was just trying to demonstrate the simplest approach
possible, but it's worth the few extra lines of code to do it right.
Avoiding the extra memory isn't the main problem here - it's
correctness. The extra speed and memory efficiency of the "brute
force" solution I suggested (which I think is actually simpler too,
fundamentally - it doesn't involve the concepts of text conversion etc)
are just bonuses.