为什么字典在动态规划期间“不包含‘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;
我们应该在 textbox1 上得到结果“false”
但是我们会得到运行时错误:“不包含‘ElementAt’的定义”
如果你要输入:
Dictionary<string, dynamic> var1 = D2.ElementAt(1).Value;
textBox1.Text += var1.ElementAt(1).Value;
然后就可以正常工作了!
另一个解决方案,对我来说,我需要添加对 System.Linq 的引用并且一切正常,无需修改所需的代码。
我是一名优秀的程序员,十分优秀!