I have a class like this:
public class Foo<T> : IEquatable<T> where T : struct
{
List<T> lst;
[Other irrelevant member stuff]
}
I want to implement the IEquatable<T>
interface for the Foo class. What do I need to do. For simplicity I want to just check whether the List members are equal.
Thanks.
C# 4.0 supported answers are allowable.
Update: Here is what I currently have:
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));
}
I get this error:
Error 1 'Foo<T>' does not implement interface member 'System.IEquatable<T>.Equals(T)