Linq to XML -Dictionary转换
如何将以下节点存储到Dictionary中,其中int是使用LINQ的自动生成的Key和字符串(节点的值)?
Elements:
XElement instructors = XElement.Parse( @" Daniel Joel Eric Scott Joehan " );
partially attempted code is given below :
var qry = from instr in instructors.Elements("instructor") where((p,index)=> **incomplete**).select..**incomplete**;
如何将我的选择转换为Dictionary
? (键应从1开始;在Linq标记从零开始)。
怎么样:
var dictionary = instructors.Elements("instructor") .Select((element, index) => new { element, index }) .ToDictionary(x => x.index + 1, x => x.element.Value);