I have a data table that looks like this (Not my table can't change the data)
Code Version Description
AAA 0.0.0.0 Test of AAA
AAA 0.0.0.1 Test of AAA
BBB 0.0.0.0 Test of BBB
CCC 0.0.0.0 Test of CCC
CCC 0.0.0.1 Test of CCC
I want to return a list of unique "Code" values only.
So my desired result will be:
AAA Test of AAA
BBB Test of BBB
CCC Test of CCC
I've created a comparer class:
public class MyComparer : IEqualityComparer<MY_DATA_TABLE>
{
public bool Equals(MY_DATA_TABLE x, MY_DATA_TABLE y)
{
return x.CODE == y.CODE;
}
public int GetHashCode(MY_DATA_TABLE obj)
{
return obj.GetHashCode();
}
}
and in my code I have:
var mapCodes = (from mtc in GetAllData() select mtc)
.Distinct(new MyComparer ())
.ToList();
However it is still returning the entire contents back.
How can I achieve getting a distinct list by property?