একটি ফাইলে একটি অ্যারে লিখতে 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