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