I have a C# application that loads a List of CLR objects called \"Tasks\". Each Task has the following properties:
public int ID { get; set; }
public int Typ
You need to implement your own comparer:
public class TaskComparer : IEqualityComparer
{
#region IEqualityComparer Members
public bool Equals(Task x, Task y)
{
return x.TypeID == y.TypeID && x.TypeName == y.TypeName;
}
public int GetHashCode(Task obj)
{
return obj.TypeID.GetHashCode() + obj.TypeName.GetHashCode();
}
#endregion
}
Then use it like this:
var uniqueTasks = allTasks.Distinct(new TaskComparer());
EDIT: Hacked out some GetHashCode() thanks to Slaks who pointed out that GetHashCode is absolutely necessary (I guess it builds a HashTable internally)