Ire*_*311 2 c# dictionary dynamic
为什么动态编程期间字典“不包含‘ElementAt’的定义”
Dictionary<string, dynamic> D1 = new Dictionary<string, dynamic>();
D1.Add("w1", 10);
D1.Add("w2", false);
Dictionary<string, dynamic> D2 = new Dictionary<string, dynamic>();
D2.Add("v1", 10);
D2.Add("v2", D1);
textBox1.Text += D2.ElementAt(1).Value.ElementAt(1).Value;
Run Code Online (Sandbox Code Playgroud)
我们应该在 textbox1“false”上得到结果
,但是我们会得到运行时错误:“不包含‘ElementAt’的定义”
如果您输入:
Dictionary<string, dynamic> var1 = D2.ElementAt(1).Value;
textBox1.Text += var1.ElementAt(1).Value;
Run Code Online (Sandbox Code Playgroud)
然后就可以正常工作了!