c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -


i have following code -

dictionary<string, string> mydict = new dictionary<string, string>();  mydict.add("keya", "valuea"); mydict.add("keyb", "valueb");  ienumerable<selectlistitem> myselectlist = new selectlist(mydict, "key", "value") 

further down in program, want add values mydict. possible? if yes, how? want -

myselectlist.mydict.add("keyc", "valuec"); 

if you're wanting add items mydict, possible, , changes reflected in of myselectlist's enumerations long changes made before enumeration (e.g. using .tolist()) generated.

as worked example:

        dictionary<string, string> mydict = new dictionary<string, string>();          mydict.add("keya", "valuea");         mydict.add("keyb", "valueb");          ienumerable<selectlistitem> myselectlist = new selectlist(mydict, "key", "value");          mydict.add("keyc", "valuec");          var result = myselectlist.tolist();        // result list containing 3 items - keya, keyb , keyc.          mydict.add("keyd", "valued");          var result2 = myselectlist.tolist();        // result2 list containing 4 items. result       // unchanged, containing original three. 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -