C# find duplicate in list
Last modified: June 29, 2021class Phone
{
public string model { get; set; }
public double price { get; set; }
}
static void Main(string[] args)
{
var list = new List<string>() { "a", "b", "c", "a" };
var query = list.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(y => y.Key)
.ToList(); //output a
var phones = new List<Phone>() {
new Phone { model = "iPhone11", price = 888.80 },
new Phone {model="iphone12", price=999.99 },
new Phone { model = "iPhone11", price = 888.80 }};
var query2 = phones.GroupBy(x => x.model)
.Where(g => g.Count() > 1)
.Select(y => y.Key)
.ToList();
}