using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
var input = new List<MyClass>
new MyClass { Id = 1, Name = "John", Type = "primary" },
new MyClass { Id = 2, Name = "John", Type = "secondary" },
new MyClass { Id = 3, Name = "Joe", Type = "primary" },
new MyClass { Id = 4, Name = "Jim", Type = "primary" }
var output = input.GroupBy(x => x.Name).Select(x => (x.Count() > 1) ? x.FirstOrDefault(y => y.Type == "primary") : x.FirstOrDefault()).ToList();
Console.WriteLine(string.Join("\n", output.Select(x => $"Id = {x.Id}, Name = {x.Name}, Type = {x.Type}")));
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }