XML Serialization in C#

前端 未结 7 1517
别那么骄傲
别那么骄傲 2021-02-08 17:37

Where Can I find good tutorial about XMl serialization to the object? Thanks.

7条回答
  •  清歌不尽
    2021-02-08 18:21

    There's a basic tutorial on Microsoft's support pages and their code example is only a few lines long:

    using System;
    
    public class clsPerson
    {
      public  string FirstName;
      public  string MI;
      public  string LastName;
    }
    
    class class1
    { 
       static void Main(string[] args)
       {
          clsPerson p=new clsPerson();
          p.FirstName = "Jeff";
          p.MI = "A";
          p.LastName = "Price";
          System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType());
          x.Serialize(Console.Out, p);
          Console.WriteLine();
          Console.ReadLine();
       }
    }
    

    Basically you don't have to anything other than call the built in functions that do all the hard work for you.

提交回复
热议问题