I think this pattern is what you are looking for:
using System;
using System.Collections.Generic;
namespace KeyValuePair
{
class Program
{
static void Main(string[] args)
{
List<KeyValuePair<string, string>> listImport = new List<KeyValuePair<string, string>>();
listImport.Add(new KeyValuePair<string, string>("K1", "CCC"));
listImport.Add(new KeyValuePair<string, string>("K2", "BBB"));
listImport.Add(new KeyValuePair<string, string>("K3", "AAA"));
listImport.Add(new KeyValuePair<string, string>("K4", "BBB"));
listImport.Sort(delegate(KeyValuePair<string, string> first, KeyValuePair<string, string> second)
{
return first.Value.CompareTo(second.Value);
});
// We only need to "remember" the last value because the KeyValuePair list is sorted.
string strLast = String.Empty;
List<string> listDistinct = new List<string>();
foreach (KeyValuePair<string, string> kvp in listImport)
{
if (strLast == kvp.Value)
continue;
listDistinct.Add(kvp.Value);
strLast = kvp.Value;
}
foreach (string str in listDistinct)
Console.WriteLine(str);
Console.ReadKey();
}
}
}