ভ্যালুগুলোর জন্য স্ট্রিং অ্যারে সেট করুন −
string[] names = new string[] {"Jack", "Tom"};এখন foreach অ্যারে ব্যবহার করে ফাইলে কন্টেন্ট লিখুন −
using (StreamWriter sw = new StreamWriter("names.txt")) { foreach (string s in names) { sw.WriteLine(s); } }স্ট্রিমের অ্যারে ব্যবহার করে ফাইলে টেক্সট লিখার উদাহরণ নিচে দেওয়া হলো −
উদাহরণ
using System; using System.IO; namespace FileApplication { class Program { static void Main(string[] args) { string[] names = new string[] {"Jack", "Tom"}; using (StreamWriter sw = new StreamWriter("names.txt")) { foreach (string s in names) { sw.WriteLine(s); } } // ফাইল থেকে প্রতিটি লাইন পড়ে দেখান string line = ""; using (StreamReader sr = new StreamReader("names.txt")) { while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } } Console.ReadKey(); } } }