Linq to XML -Dictionary conversion

前端 未结 1 891
抹茶落季
抹茶落季 2021-01-18 15:38

How to store the nodes of the following into Dictionary where int is an autogenerated Key and string (value of the node) using LINQ ?

Elements

1条回答
  •  伪装坚强ぢ
    2021-01-18 15:57

    How about:

    var dictionary = instructors.Elements("instructor")
                                .Select((element, index) => new { element, index })
                                .ToDictionary(x => x.index + 1,
                                              x => x.element.Value);
    

    0 讨论(0)
提交回复
热议问题