सबसे पहले, एक स्ट्रिंग ऐरे और StringBuilder सेट करें -
// string array
string[] myStr = { "One", "Two", "Three", "Four" };
StringBuilder str = new StringBuilder("We will print now...").AppendLine(); अब, पुनरावृति करने के लिए फ़ोरैच लूप का उपयोग करें -
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