Since the linked list is not a dictionary, I would expect it to use EqualityComparer<T>.Default.Equals(x,y).
This supports (in order):
IEquatable<T>(for T)object.Equals(which uses referential equality by default or supports redefinition Equals(object))
, EqualityComparer<T> null .. Nullable<T>.
(: , Find(T))
...
EqualityComparer<T> comparer = EqualityComparer<T>.Default;
...
if (comparer.Equals(head.item, value)) {...}
...
, , , ISomeInterface: IEquatable<ISomeInterface>, :
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
LinkedList<IFoo> foos = new LinkedList<IFoo>();
foos.AddLast(new Foo1("abc"));
foos.AddLast(new Foo2("def"));
Console.WriteLine("checking contains...");
bool c = foos.Contains(new Foo1("ghi"));
Console.WriteLine("...done");
}
}
interface IFoo : IEquatable<IFoo>
{
void Bar();
}
class Foo1 : IFoo
{
public string Value { get; set; }
public Foo1(string value) { Value = value; }
public override bool Equals(object other)
{
Console.WriteLine(Value + " > override Equals");
return base.Equals(other);
}
bool IEquatable<IFoo>.Equals(IFoo other)
{
Console.WriteLine(Value + " > explicit Equals");
return base.Equals(other);
}
public void Bar() { }
public override int GetHashCode() { return base.GetHashCode(); }
}
class Foo2 : IFoo
{
public string Value { get; set; }
public Foo2(string value) { Value = value; }
public override bool Equals(object other)
{
Console.WriteLine(Value + " > override Equals");
return base.Equals(other);
}
public bool Equals(IFoo other)
{
Console.WriteLine(Value + " > implicit Equals");
return base.Equals(other);
}
public void Bar() { }
public override int GetHashCode() { return base.GetHashCode(); }
}