简体   繁体   中英

I need to save multiple items in a List<> in a .txt file, how can I do that? I don't have any code to show atm :')

    private void btnOpslaan_Click(object sender, EventArgs e)
    {
        
    }

First add System.IO namespace to the code.

using System.IO;

Then use this line:

File.WriteAllLines(@"c:\YourFileName.txt", yourList);

Creates a new file, writes a collection of strings to the file, and then closes the file.

Be careful, If the target file already exists, it will overwritten. If you want to append lines, try ' File.AppendAllLines ' method.

More about File.WriteAllLines

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