我想要一个包含所有控件的名称和文本的字典。是否可以使用预定义的框架方法/LINQ/集合初始值设定项,还是我必须自己创建一个循环并添加所有条目?
这给了我一条错误消息:
List<Control> controls;
// .. initialize list ..
controls.ToDictionary((Control child,string k)=>new KeyValuePair<string,string>(child.Name, child.Text));
最佳答案
调用应该是这样的:
controls.ToDictionary(
c => c.Name, // Key selector
c => c.Text); // Element selector.
关于c# - 从列表<Control>获取字典<string,string>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2628977/