In C# how do I get a list of the keys from a dictionary?
I have the following code:
Dictionary <string, decimal> inventory;
// this is passed in as a parameter. It is a map of name to price
// I want to get a list of the keys.
// I THOUGHT I could just do:
List<string> inventoryList = inventory.Keys.ToList();
But I get the following error:
'System.Collections.Generic.Dictionary.KeyCollection' does not contain a
definition for 'ToList' and no extension method 'ToList' accepting a first
argument of type 'System.Collections.Generic.Dictionary.KeyCollection'
could be found (are you missing a using directive or an assembly
reference?)
Am I missing a using directive? Is there something other than
using System.Collections.Generic;
that I need?
No comments:
Post a Comment