I have the following class
public class ModInfo : IEquatable<ModInfo>
{
public int ID { get; set; }
public string MD5 { get; set; }
public bool Equals(ModInfo other)
{
return other.MD5.Equals(MD5);
}
public override int GetHashCode()
{
return MD5.GetHashCode();
}
}
I load some data into the list of this class using the following method:
public void ReloadEverything() {
var beforeSort = new List<ModInfo>();
var modinfo = beforeSort.OrderBy(m => m.ID).AsEnumerable().Distinct().ToList();
}
The problem is that the call Distinct()does not do this work. There are still objects that are equal to each other.
According to this article: https://msdn.microsoft.com/en-us/library/vstudio/bb348436%28v=vs.100%29.aspx
this is how you should do an excellent job, however it looks like it does not call the Equals method of the ModInfo object. What could be the reason for this?
Example values:
modinfo[0]: id=2069, MD5 =0AAEBF5D2937BDF78CB65807C0DC047C
modinfo[1]: id=2208, MD5 = 0AAEBF5D2937BDF78CB65807C0DC047C
I don’t care what value is chosen, they are likely to be the same, since the md5 value will be the same.
source
share