You don't really need the list; it looks totally redundant. The only possible reason to iterate by the keys is when you need to preserve the order of items, and the right order is represented by the order in the list, which is not the same as the order in the dictionary, [EDIT] of the list contains only a subset of the keys, as you correctly noted in your comment. It's very good that you know the purpose [END EDIT].
Nevertheless, you can do it. As I can see, your only problem is getting a value by a key. In your loop, your key is
a
and, as getting the dictionary value from the dictionary is the main feature of the dictionary, please look at MSDN help page and see how to do it. You can use the
indexed property, using, in C#, '[]' syntax. And read about indexed properties in C# reference. This should be more than enough.
However, as I say, you are rather advised to ignore your list (see my first paragraphs) and iterate using
foreach(var pair in yourDictionary) { /* ... */ }
, where
pair
will be:
http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx[
^].
This is really all what you need, event more than that.
I hope you understand why I'm not showing any code. If you don't do such trivial things with your own hands, most likely, after looking at the code, your skills will remain on the same level, called "next to nothing", which I think is not what you want.
Thank you for understanding, good luck,
—SA