c# - exception on accessing dictionary from list -
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace test { class program { static void main(string[] args) { list<object> list = new list<object>(); list<dictionary<string, object>> dict = new list<dictionary<string, object>>(); dictionary<string, object> master = new dictionary<string, object>(); master.add("list", list); master.add("dict", dict); list<object> mydict = (list<object>)master["dict"]; // exception console.write("count: ", mydict.count); } } }
it throwing exception on bold line. why behaviour , how shall access element? sumanth
because there no list<object>
under dict key
var mydict = (list<dictionary<string, object>>)master["dict"];
Comments
Post a Comment