How to convert Dictionary keys or values to a List

I once had a requirement that I needed to dynamically build a select statement, based on a users selection and then display the results in a DataGrid. The tricky part was that the column name in the select portion of the query was not always the name I needed to show as the column heading in the DataGrid..

The solution was to use a dictionary and store the selected column which I would use in the SQL query as the KEY and the column name which I would show as the DataGrid column name as the VALUE.

It works just fine and I am certain there will never be 2 identical selectable columns stored as the KEY. Then what I had to do was extract the data in the KEY portion of the dictionary to build my SELECT portion of the query and then the VALUE portion of the dictionary to build my DataGrid columns.

Below is not the code I used for the above, but it shows the concepts I implemented.

List<string> guitarBuilder = coolDictionary
                                  .Values
                                  .ToList<string>();
List<string> guitarModel = coolDictionary
                                .Keys
                                .ToList<string>();

The coolDictionary is the Dictionary that contains my KEY/VALUE pairs. You see that I can convert either the KEYS or the VALUES to a List of strings with one line of code.

Once I do the above, I can use the List just as I would any other list to iterate through the data.

foreach (var builder in guitarBuilder)
{
     Console.WriteLine(builder);
}

Download the source