The Microsoft documentation for
public bool Binary.Equals(Binary other)
gives no indication as to whether this tests equality of reference as with objects in general or equality of value as with strings.
Can anyone clarify?
John Skeet's answer inspired me to expand it to this:
using System;
using System.Data.Linq;
public class Program
{
static void Main(string[] args)
{
Binary a = new Binary(new byte[] { 1, 2, 3 });
Binary b = new Binary(new byte[] { 1, 2, 3 });
Console.WriteLine("a.Equals(b) >>> {0}", a.Equals(b));
Console.WriteLine("a {0} == b {1} >>> {2}", a, b, a == b);
b = new Binary(new byte[] { 1, 2, 3, 4 });
Console.WriteLine("a {0} == b {1} >>> {2}",a,b, a == b);
/* a < b is not supported */
}
}
Well, a simple test suggests it is value equality:
using System;
using System.Data.Linq;
class Program {
static void Main(string[] args)
{
Binary a = new Binary(new byte[] { 1, 2, 3 });
Binary b = new Binary(new byte[] { 1, 2, 3 });
Console.WriteLine(a.Equals(b)); // Prints True
}
}
The fact that they've bothered to implement IEquatable<Binary> and override Equals(object) to start with suggests value equality semantics too... but I agree that the docs should make this clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With