using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
public static void Main()
var f1 = new Foo(new[] { 1, }.ToImmutableArray());
var f2 = new Foo(new[] { 1, }.ToImmutableArray());
var f3 = new Foo(new[] { 1, 2, }.ToImmutableArray());
Console.WriteLine("f1 == f2: {0}", f1 == f2);
Console.WriteLine("f1 == f3: {0}", f1 == f3);
Console.WriteLine("f2 == f3: {0}", f2 == f3);
Console.WriteLine("f1 hashcode: {0}", f1.GetHashCode());
Console.WriteLine("f2 hashcode: {0}", f2.GetHashCode());
Console.WriteLine("f3 hashcode: {0}", f3.GetHashCode());
var b1 = new Bar(new[] { 1, });
var b2 = new Bar(new[] { 1, });
var b3 = new Bar(new[] { 1, 2, });
Console.WriteLine("b1 == b2: {0}", b1 == b2);
Console.WriteLine("b1 == b3: {0}", b1 == b3);
Console.WriteLine("b2 == b3: {0}", b2 == b3);
Console.WriteLine("b1 hashcode: {0}", b1.GetHashCode());
Console.WriteLine("b2 hashcode: {0}", b2.GetHashCode());
Console.WriteLine("b3 hashcode: {0}", b3.GetHashCode());
record Foo(ImmutableArray<int> Arr)
public virtual bool Equals(Foo other)
if ((object)this != other)
if ((object)other != null && EqualityContract == other.EqualityContract)
var comparer = StructuralComparisons.StructuralEqualityComparer;
return comparer.Equals(Arr, other.Arr);
public override int GetHashCode()
var comparer = StructuralComparisons.StructuralEqualityComparer;
return (EqualityComparer<Type>.Default.GetHashCode(this.EqualityContract) * -1521134295)
+ comparer.GetHashCode(this.Arr);
public virtual bool Equals(Bar other)
if ((object)this != other)
if ((object)other != null && EqualityContract == other.EqualityContract)
var comparer = StructuralComparisons.StructuralEqualityComparer;
return comparer.Equals(Arr, other.Arr);
public override int GetHashCode()
var comparer = StructuralComparisons.StructuralEqualityComparer;
return (EqualityComparer<Type>.Default.GetHashCode(this.EqualityContract) * -1521134295)
+ comparer.GetHashCode(this.Arr);