The List class does not support multiple dimensions. Read more about it here:
<list> (C# Programming Guide) | Microsoft Docs[
^]
If you want to use a List class, then you can use a Array, Class,
[
^]Tuple or
KeyValuePair[
^] to store your values. For this solution I will use the List<keyvaluepair> as you have non-unique keys. The
Dictionary[
^] class requires unique keys so is not suitable.
var list = new List<KeyValuePair<int, string>>
{
new KeyValuePair<int, string> (100, "abc"),
new KeyValuePair<int, string> (101, "zzz"),
new KeyValuePair<int, string> (103, "aaa"),
new KeyValuePair<int, string>(100, "yyy")
};
var results = list.GroupBy(x => x.Key)
.Where(x => x.Count() == 1)
.Select(x => x.First());
foreach (var item in results)
{
Console.WriteLine($"Key: {item.Key} Value: {item.Value}");
}
The Linq expression will group by the Key field, when where there is only 1 unique result per grouping, select the first entry.