2009-07-28 45 views

回答

10

XML序列化:

ObservableCollection<Customer> customers = new ObservableCollection<Customer>(); 
... 

XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection<Customer>)); 
using (StreamWriter wr = new StreamWriter("customers.xml")) 
{ 
    xs.Serialize(wr, customers); 
} 

要重新加載該文件中的數據:

XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection<Customer>)); 
using (StreamReader rd = new StreamReader("customers.xml")) 
{ 
    customers = xs.Deserialize(rd) as ObservableCollection<Customer>; 
} 
+0

請你告訴我你是怎麼得到它的工作,下的StreamWriter( 「customers.xml」)我不斷收到一條錯誤消息:「參數1:無法從'字符串'轉換爲'System.IO.Stream'」 – 2016-07-20 14:21:39

相關問題