C# Implementierung von IEquatable<T>.Gleich<T>

Habe ich eine Klasse wie folgt aus:

public class Foo<T> : IEquatable<T> where T : struct
{
    List<T> lst;
    [Other irrelevant member stuff]
}

Ich soll zur Umsetzung der IEquatable<T> Schnittstelle für die Klasse "Foo". Was muss ich tun. Einfachheit halber möchte ich nur prüfen, ob die Liste der Mitglieder gleich sind.

Dank.

C# 4.0 unterstützt Antworten sind zulässig.

Update: Hier ist, was ich derzeit habe:

public bool Equals(Foo<T> foo)
{
    return lst.Equals(foo.lst);
}

public override bool Equals(Object obj)
{
    if (obj == null) return base.Equals(obj);

    if (!(obj is Foo<T>))
    {
        throw new Exception("The 'obj' argument is not a Foo<T> object.");
    }
    else
    {
            return Equals(obj as Foo<T>)
    }
}    

public override int GetHashCode()
{
    return this.lst.GetHashCode();
}

public static bool operator ==(Foo<T> f1, Foo<T> f2)
{
   return f1.Equals(f2);
}

public static bool operator !=(Foo<T> f1, Foo<T> f2)
{
   return (!f1.Equals(f2));
}

Bekomme ich diesen Fehler:

Error 1 'Foo<T>' does not implement interface member 'System.IEquatable<T>.Equals(T)
InformationsquelleAutor Chris | 2010-01-17
Schreibe einen Kommentar