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