简体   繁体   中英

C# Saving an arraylist to a file?

I have a simple program where I would like to save an arraylist to a file, so that when the program is restarted, it loads from the file to the arraylist in memory.

Is this possible in C#? Or do I need to itterate over the arraylist countaining my custom classes and in someway print them out?

Any tips on a correct way to do this?

You will want to look into Serialization. Here's a link to get you going.

是的,而不是ArrayList,而是使用List <T>并将数据存储在XML文件中。程序启动时,读取该XML文件。

Look at the DeSerializeObject and SerializeObject methods in this post

http://weblogs.asp.net/rajbk/archive/2009/10/04/xmlserializer-and-invalid-xml.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM