zoukankan      html  css  js  c++  java
  • XmlSerializer序列化一组成员到文本文件

    写入:

    using (System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (System.IO.IsolatedStorage.IsolatedStorageFileStream fs = isf.CreateFile(fileName))
                    {
                        System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(List<TripInfo>));
                        ser.Serialize(fs, Trips);
                    }
                }

    读取:

    List<TripInfo> trips = null;
                System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(List<TripInfo>));
                object obj = ser.Deserialize(fs);
                if (null != obj && obj is List<TripInfo>)
                {
                    trips = obj as List<TripInfo>;
                }
                else
                {
                    trips = new List<TripInfo>();
                }

  • 相关阅读:
    0593. Valid Square (M)
    0832. Flipping an Image (E)
    1026. Maximum Difference Between Node and Ancestor (M)
    0563. Binary Tree Tilt (E)
    0445. Add Two Numbers II (M)
    1283. Find the Smallest Divisor Given a Threshold (M)
    C Primer Plus note9
    C Primer Plus note8
    C Primer Plus note7
    C Primer Plus note6
  • 原文地址:https://www.cnblogs.com/binaryworms/p/2620456.html
Copyright © 2011-2022 走看看