how to get a list( as a value) from dictionay using C#
Dictionary have a List as a value.
I want to get that List from dictionary.
Eg: Dicti开发者_JS百科onary(boolean, List) dic =new Dictionary(boolean, List)();
get a list from dic.
use
List list = dictionary[<key>];
where is the key that was used to store the list.
Or do you mean you want the list of all values that the dictionary has? In which case you want something like:
IList list=new ArrayList (dictionary.Values);
given your updated question if you have a dictionary which has 2 lists keyed by a bool then you just want to do:
List list = dictionary[true];
or
List list = dictionary[false];
First you need to add a list to your dictionary
var boolListDict = new Dictionary<bool, List>()
boolListDict[true] = new List();
then you can retrieve the list like so:
List truelist = boolListDict[true];
精彩评论