我有ArrayListnabídka,我必須使用流編寫器保存從此ArrayList到XML文件的所有內容,並在啓動應用程序時使用流讀取器將XML文件加載到ArrayList。有人知道該怎麼做嗎? (是的,我知道我不應該不使用ArrayList,但我必須同它完成這個項目。)保存ArrayList值爲XML C#
-3
A
回答
2
繼承人的它可能如何實現
ArrayList sampleList = new ArrayList();
sampleList.Add(" ");
//Add your elements
//StreamWriter initialized with append mode
StreamWriter streamwriter = new StreamWriter(" INSERT PATH OF XML HERE ", true);
for (int i = 0; i < sampleList.Count; i++)
{
//Elements are written into the file here, remember not to forget the xml structure
streamwriter.WriteLine(sampleList[i]);
}
//You have to close the streamwriter or you have to flush to make sure the text is saved
streamwriter.Close();
我希望我可以幫你
爲例
0
也是可能的:
var xmlSerializer = new XmlSerializer(typeof(ArrayList), new Type[] { typeof(YourType) });
但其序列將是更好的有一個List<t>
。 序列化的好處是易於閱讀,甚至可以在語言/應用程序之間輕鬆共享整個對象。
相關問題
- 1. 將ArrayList保存爲XML文件
- 2. 如何ArrayList中保存爲XML
- 3. 將arraylist值保存到txt C#
- 4. Android:保存ArrayList中的值
- 5. MySQL查詢到C#與保存爲XML
- 6. c#2保存爲xml的參數
- 7. C#應用程序不保存爲xml
- 8. C# - 將數據集保存爲XML
- 9. C#無法將撇號保存爲XML
- 10. 保存的CheckBoxList價值爲xml用vb.net
- 11. 解析XML文檔並保存爲arraylist或替代
- 12. ArrayList的使用對象不保存值
- 13. ArrayList中不保存我的價值觀
- 14. 保存並恢復ArrayList中的值
- 15. 保存XML數據在C#
- 16. Android將ArrayList <Object>保存爲SharedPreference
- 17. 確保值存在從XML
- 18. 保存ArrayList項目
- 19. java mongo arraylist保存
- 20. 將JSON轉換爲XML並保存XML
- 21. 如何使用c#將xml中的值轉換爲arraylist?
- 22. VB.net/asp.net:將Session保存爲ArrayList
- 23. 將ArrayList保存爲CSV文件Apache Wicket
- 24. Python將Unicode保存爲XML
- 25. 將數組保存爲xml
- 26. 將Open XML保存爲PDF
- 27. 保存爲XML與VBA?
- 28. 保存的UIView爲XML
- 29. ArrayList通過屬性對象ArrayList保存?
- 30. 保存並讀取arraylist的arraylist類
XML文件的格式是什麼?你到目前爲止嘗試了什麼?你到底在哪裏遇到問題? –
查看XElement它真的很容易。 – progpow
你應該先嚐試一下,並開始一些谷歌搜索...並描述你的努力也.. – vikky