如何在C#中编写文本文件 [英] How to write a text file in C#

查看:72
本文介绍了如何在C#中编写文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从C#向文本文件中写入一个字符串,每个字符串都换一行...该如何做?

I need to write a strings into a text file from C#, each string on a new line...How can I do this?

推荐答案

您可以使用 File.WriteAllLines :

string[] mystrings = new string[] { "Foo", "Bar", "Baz", "Qux" };

System.IO.File.WriteAllLines("myfile.txt", mystrings);

这篇关于如何在C#中编写文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆