using System;
using System.Collections.Generic;
using System.Linq;
class Sample
{
public string Value1 { get; set; }
public string Value2 { get; set; }
public override string ToString() {
return Value1 + "/" + Value2;
}
public override int GetHashCode()
{
return Value2.GetHashCode();
}
public override bool Equals(object obj)
{
var other = obj as Sample;
return other == null ? false : this.Value2 == other.Value2;
}
}
public class Test
{
public static void Main()
{
var list = new List<Sample>() {
new Sample{ Value1 = "Apple", Value2="Red" },
new Sample{ Value1 = "Banana", Value2="Yellow" },
new Sample{ Value1 = "Lemon", Value2="Yellow" },
};
list = list.Distinct().ToList();
foreach (var n in list) {
Console.WriteLine(n);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CgpjbGFzcyBTYW1wbGUKewogICAgcHVibGljIHN0cmluZyBWYWx1ZTEgeyBnZXQ7IHNldDsgfQogICAgcHVibGljIHN0cmluZyBWYWx1ZTIgeyBnZXQ7IHNldDsgfQogICAgcHVibGljIG92ZXJyaWRlIHN0cmluZyBUb1N0cmluZygpIHsKICAgICAgICByZXR1cm4gVmFsdWUxICsgIi8iICsgVmFsdWUyOwogICAgfQogICAgCiAgICBwdWJsaWMgb3ZlcnJpZGUgaW50IEdldEhhc2hDb2RlKCkKICAgIHsKICAgICAgICByZXR1cm4gVmFsdWUyLkdldEhhc2hDb2RlKCk7CiAgICB9CiAgICBwdWJsaWMgb3ZlcnJpZGUgYm9vbCBFcXVhbHMob2JqZWN0IG9iaikKICAgIHsKICAgICAgICB2YXIgb3RoZXIgPSBvYmogYXMgU2FtcGxlOwogICAgICAgIHJldHVybiBvdGhlciA9PSBudWxsID8gZmFsc2UgOiB0aGlzLlZhbHVlMiA9PSBvdGhlci5WYWx1ZTI7CiAgICB9Cn0KCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQl2YXIgbGlzdCA9IG5ldyBMaX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