gpt4 book ai didi

c# - 为什么字典 "does not contain a definition for ' ElementAt'”?

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:33 24 4
gpt4 key购买 nike

为什么字典在动态规划期间“不包含‘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 的引用并且一切正常,无需修改所需的代码。

关于c# - 为什么字典 "does not contain a definition for ' ElementAt'”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32997696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com