Use WriteAllLines method to write an array to a file.
Firstly, set a string array −
string[] stringArray = new string[] { "one", "two", "three" };
Now, use the WriteAllLines method to add the above array to a file −
File.WriteAllLines("new.txt", stringArray);
Here is the complete code −
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