How to write a text file in C#

前端 未结 4 627
抹茶落季
抹茶落季 2020-12-07 02:48

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

4条回答
  •  独厮守ぢ
    2020-12-07 03:39

    You can use File.WriteAllLines:

    string[] mystrings = new string[] { "Foo", "Bar", "Baz", "Qux" };
    
    System.IO.File.WriteAllLines("myfile.txt", mystrings);
    

提交回复
热议问题