Suppose you have a list of MyObject like this:
public class MyObject
{
public int ObjectID {get;set;}
public string Prop1 {get;set;}
}
You could create a custom object comparer by implementing the IEqualityComparer interface:
public class MyObject
{
public int Number { get; set; }
}
public class MyObjectComparer : IEqualityComparer
{
public bool Equals(MyObject x, MyObject y)
{
return x.Id == y.Id;
}
public int GetHashCode(MyObject obj)
{
return obj.Id.GetHashCode();
}
}
Then simply:
myList.Distinct(new MyObjectComparer())