using System.Collections.Generic;
public class StudentTestData {
public string AccessionNumber { get;set; }
public string LoginId { get; set; }
public class CustomComparer<T> : IEqualityComparer<T> {
private readonly Func<T, object> _match;
public CustomComparer(Func<T, object> match) {
public bool Equals(T data1, T data2) {
return object.Equals(_match(data1), _match(data2));
public int GetHashCode(T data) {
var matchValue = _match(data);
if (matchValue == null) {
return matchValue.GetHashCode();
public static void Main()
var data = new List<StudentTestData>() {
var accessComparer = new CustomComparer<StudentTestData>(d => d.AccessionNumber );
var loginComparer = new CustomComparer<StudentTestData>(d => d.LoginId );
Console.WriteLine("Per accession number");
foreach (var d in data.Distinct( accessComparer )) {
Console.WriteLine( "{0}, {1}", d.AccessionNumber, d.LoginId);
Console.WriteLine("Per login number");
foreach (var d in data.Distinct( loginComparer )) {
Console.WriteLine( "{0}, {1}", d.AccessionNumber, d.LoginId);