প্রথমত, একটি স্ট্রিং অ্যারে এবং স্ট্রিংবিল্ডার -
সেট করুন// string array
string[] myStr = { "One", "Two", "Three", "Four" };
StringBuilder str = new StringBuilder("We will print now...").AppendLine(); এখন, −
পুনরাবৃত্তি করতে foreach লুপ ব্যবহার করুনforeach (string item in myStr) {
str.Append(item).AppendLine();
} নিম্নলিখিত সম্পূর্ণ কোড -
উদাহরণ
using System;
using System.Text;
public class Demo {
public static void Main() {
// string array
string[] myStr = { "One", "Two", "Three", "Four" };
StringBuilder str = new StringBuilder("We will print now...").AppendLine();
// foreach loop to append elements
foreach (string item in myStr) {
str.Append(item).AppendLine();
}
Console.WriteLine(str.ToString());
Console.ReadLine();
}
} আউটপুট
We will print now... One Two Three Four