How to read a XML file and write into List<>?

后端 未结 5 1438
自闭症患者
自闭症患者 2020-12-09 05:09

I have a List<> which I have managed to write into file. Now I am trying to read the same file and write it back to List<>. Is there a

5条回答
  •  温柔的废话
    2020-12-09 05:42

    An easy way is

    using System;
    using System.Linq;
    using System.Xml.Linq;
    
    public class Test
    {
        static void Main()
        {
            string xml = "12";
    
            XDocument doc = XDocument.Parse(xml);
    
            List list = doc.Root.Elements("id")
                               .Select(element => element.Value)
                               .ToList();
    
    
        }
    }
    

提交回复
热议问题