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 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" },
};
var s = new HashSet<string>();
list = list.Where(n => s.Add(n.Value2)).ToList();
foreach (var n in list) {
Console.WriteLine(n);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CgpjbGFzcyBTYW1wbGUKewogICAgcHVibGljIHN0cmluZyBWYWx1ZTEgeyBnZXQ7IHNldDsgfQogICAgcHVibGljIHN0cmluZyBWYWx1ZTIgeyBnZXQ7IHNldDsgfQogICAgcHVibGljIG92ZXJyaWRlIHN0cmluZyBUb1N0cmluZygpIHsKICAgICAgICByZXR1cm4gVmFsdWUxICsgIi8iICsgVmFsdWUyOwogICAgfQp9CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJdmFyIGxpc3QgPSBuZXcgTGlzdDxTYW1wbGU+KCkgeyAKICAgICAgICAgICAgbmV3IFNhbXBsZXsgVmFsdWUxID0gIkFwcGxlIiwgVmFsdWUyPSJSZWQiIH0sCiAgICAgICAgICAgIG5ldyBTYW1wbGV7IFZhbHVlMSA9ICJCYW5hbmEiLCBWYWx1ZTI9IlllbGxvdyIgfSwKICAgICAgICAgICAgbmV3IFNhbXBsZXsgVmFsdWUxID0gIkxlbW9uIiwgVmFsdWUyPSJZZWxsb3ciIH0sCiAgICAgICAgfTsKICAgICAgICAKICAgICAgICB2YXIgcyA9IG5ldyBIYXNoU2V0PHN0cmluZz4oKTsKICAgICAgICBsaXN0ID0gbGlzdC5XaGVyZShuID0+IHMuQWRkKG4uVmFsdWUyKSkuVG9MaXN0KCk7CiAgICAgICAgCiAgICAgICAgZm9yZWFjaCAodmFyIG4gaW4gbGlzdCkgewogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZShuKTsKICAgICAgICB9CiAgICB9Cn0=