C#Linq将匿名对象选择到字典中
我创建了一个自定义配置部分,其中包含一组键值对。这一切都很好,我可以找回元素。然后,我需要做的是选择字典中的每个元素。我已经在我的C#Linq将匿名对象选择到字典中,c#,linq,configuration,ienumerable,C#,Linq,Configuration,Ienumerable,我创建了一个自定义配置部分,其中包含一组键值对。这一切都很好,我可以找回元素。然后,我需要做的是选择字典中的每个元素。我已经在我的ConfigurationCollectionElement上实现了IEnumerable,并且再次正确填充了变量元素。但是,下面的代码不会编译。错误是: “System.Collections.Generic.IEnumerable”没有 包含“ToDictionary”的定义 这显然不是事实,因为有大量的例子表明了这一点。这是怎么回事 { var prob
ConfigurationCollectionElement
上实现了IEnumerable
,并且再次正确填充了变量元素。但是,下面的代码不会编译。错误是:
“System.Collections.Generic.IEnumerable
”没有
包含“ToDictionary
”的定义
这显然不是事实,因为有大量的例子表明了这一点。这是怎么回事
{
var problemDirectory = new Dictionary<string,object>();
var coreOperands = ConfigurationManager.GetSection("RuntimeCoreOperands") as OperandConfigurationSection;
var elements = coreOperands.Operands.Select(op => new { Name = op.Name, Symbol = op.Symbol });
this.problemDirectory = elements.ToDictionary<string, object>(op => op.Name, op => op.Symbol);
}
{
var problemDirectory=new Dictionary();
var coreOperators=ConfigurationManager.GetSection(“RuntimeCoreOperators”)作为操作数配置节;
var elements=coreOperators.operators.Select(op=>new{Name=op.Name,Symbol=op.Symbol});
this.problemDirectory=elements.ToDictionary(op=>op.Name,op=>op.Symbol);
}
您是否使用System.Linq添加了代码>?尝试删除
@TimSchmelter如果符号
不是对象
,但字段类型是字典
,则没有它就无法编译。