我有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