J
JB
I've created a generic of type List<T> where T is a custom class. I
need to use the List<T>.Contains method. I know I need to implement
the IEqualityComparer but I can't seem to get the Contains method to
execute my Equals code. What am I doing wrong?
T is the following
NameValue : IEqualityComparer<NameValue>
{
public string Text;
public string Value;
public bool Equals(NameValue nv1, NameValue nv2)
{
if (nv1.Key == nv2.Key && nv1.Value == nv2.Value)
return true;
else
return false;
}
public int GetHashCode(NameValue nv)
{
return nv.Key.GetHashCode();
}
}
Thanks
JB
need to use the List<T>.Contains method. I know I need to implement
the IEqualityComparer but I can't seem to get the Contains method to
execute my Equals code. What am I doing wrong?
T is the following
NameValue : IEqualityComparer<NameValue>
{
public string Text;
public string Value;
public bool Equals(NameValue nv1, NameValue nv2)
{
if (nv1.Key == nv2.Key && nv1.Value == nv2.Value)
return true;
else
return false;
}
public int GetHashCode(NameValue nv)
{
return nv.Key.GetHashCode();
}
}
Thanks
JB