먼저 문자열 배열을 설정하고 StringBuilder -
// 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