सरणी को फ़ाइल में लिखने के लिए 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