zoukankan      html  css  js  c++  java
  • C#对XML文件的序列化和反序列化

         

    using System.Xml.Serialization;
    
    public class XMLOperate
    {
        public static void SerialXml<T>(T t, string path)
        {
            using (FileStream finfo = new FileStream(path, FileMode.Create))
            {
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add("", "");  //去除声明
                XmlSerializer se = new XmlSerializer(typeof(T));
                se.Serialize(finfo, t, ns);
            }
        }
    
        public static T DeserialXml<T>(string path)
        {
            using (FileStream stream = new FileStream(path, FileMode.Open))
            {
                XmlSerializer se = new XmlSerializer(typeof(T));
                return (T)se.Deserialize(stream);
            }
        }
    }
    


     

  • 相关阅读:
    字符串型
    字符型
    实型(浮点型)
    sizeof
    数据类型
    标识符
    Win32汇编
    Win32汇编
    C# 语言程序设计笔记
    鬼泣4:寻找无限生命/剑气/暴怒
  • 原文地址:https://www.cnblogs.com/bridgew/p/12709071.html
Copyright © 2011-2022 走看看