using System.Collections.Generic;
public class UniqueKeyKvpList : List<KeyValuePair<char, int>>
private readonly HashSet<char> _keys = new HashSet<char>();
public new void Add(KeyValuePair<char, int> kvp) => Add(kvp.Key, kvp.Value);
public void Add(char key, int value) => AddIfUniqueKey(key, value);
private void AddIfUniqueKey(char key, int value)
if (!_keys.Contains(key))
base.Add(new KeyValuePair<char, int>(key, value));
public static void Main()
var myKvpList = new UniqueKeyKvpList();
Console.WriteLine($"{nameof(myKvpList)} contains:");
Console.WriteLine(string.Join(Environment.NewLine, myKvpList));
char firstCharWithMaxValue = myKvpList
char[] charsWithMaxValue = myKvpList
.GroupBy(kvp => kvp.Value)
Console.WriteLine($"Char of first max value: {firstCharWithMaxValue}");
Console.WriteLine($"Char of entries with max value: {string.Join(", ", charsWithMaxValue)}");
char firstCharWithMaxValue_alt = myKvpList
.OrderByDescending(kvp => kvp.Value)
char[] charsWithMaxValue_alt = myKvpList
.GroupBy(kvp => kvp.Value)
.OrderByDescending(gr => gr.Key)
Console.WriteLine($"(alt) Char of first max value: {firstCharWithMaxValue_alt}");
Console.WriteLine($"(alt) Char of entries with max value: {string.Join(", ", charsWithMaxValue_alt)}");