zoukankan      html  css  js  c++  java
  • C#把类序列化成XML文件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Serialization;
    using System.Diagnostics;

    namespace ConsoleApptest
    {
        class Program
        {
            static void Main(string[] args)
            {
                Person p = new Person() {Name="jok",Age="21",Sex="" };
                Serializer(p,@"D:\Person.xml");
                Console.Read();
            }
            private static void Serializer(object type, string filename)
            {
                using (XmlWriter writer = new XmlTextWriter(filename, Encoding.UTF8))
                {
                    XmlSerializer serializer = new XmlSerializer(type.GetType());
                    serializer.Serialize(writer,type);
                }
                Process.Start(filename);
            }
        }
       public class Person
        {
            public string Name { getset; }
            public string Age { getset; }
            public string Sex { getset; }
        }
    }
  • 相关阅读:
    总结:关于作用域的经典面试题
    解决JS拖拽出现的问题
    JS正则(3)总结
    JS正则(2)对正则的理解
    JS 闭包 正则(1)
    JS Date对象
    笔记
    9.13笔记
    9.12学习笔记
    9.11学习笔记
  • 原文地址:https://www.cnblogs.com/Rmeo/p/2554302.html
Copyright © 2011-2022 走看看