将数组写入文件中的 C# 程序
使用 WriteAllLines 方法将数组写入文件。
首先,设置一个字符串数组 −
string[] stringArray = new string[] {
"one",
"two",
"three"
};现在,使用 WriteAllLines 方法将上述数组添加到文件 −
File.WriteAllLines("new.txt", stringArray);以下是完整代码 −
示例
using System.IO;
using System;
public class Program {
public static void Main() {
string[] stringArray = new string[] {
"one",
"two",
"three"
};
File.WriteAllLines("new.txt", stringArray);
using (StreamReader sr = new StreamReader("new.txt")) {
string res = sr.ReadToEnd();
Console.WriteLine(res);
}
}
}输出
one two three
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP