using System.Collections.Generic;
public static void Main()
var list = new List<DegreeResponse>()
new DegreeResponse() { Code = "1", Period = "2/2/2020" },
new DegreeResponse() { Code = "1", Period = "2/5/2020" },
new DegreeResponse() { Code = "1", Period = "2/8/2020" },
new DegreeResponse() { Code = "1", Period = "2/11/2020" },
new DegreeResponse() { Code = "1", Period = "2/2/2021" },
new DegreeResponse() { Code = "1", Period = "2/2/2021" },
new DegreeResponse() { Code = "2", Period = "2/2/2021" },
new DegreeResponse() { Code = "2", Period = "2/2/2021" },
var distinctedByCode = list.Distinct(new DegreeComparer()).ToList();
Console.WriteLine("" + distinctedByCode.Count);
public class DegreeResponse {
public string Code { get ;set;}
public string Period {get;set;}
class DegreeComparer : IEqualityComparer<DegreeResponse>
public bool Equals(DegreeResponse x, DegreeResponse y)
if (Object.ReferenceEquals(x, y)) return true;
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return x.Code == y.Code && x.Period == y.Period;
public int GetHashCode(DegreeResponse d)
if (Object.ReferenceEquals(d, null)) return 0;
int hashProductCode = d.Code == null ? 0 : d.Code.GetHashCode();