我試圖以Date-newline-Date-newline等格式打印隨機日期,但動態地添加了一些c#代碼中的日期。 我正在使用的當前代碼如下所示,用空格而不是換行符在一行中打印日期。如何動態地將新行添加到標籤c#
這裏是我當前的代碼
private void WriteDates(int NumberOfDates)
{
string dates = "";
for(int i = 0 ; i < NumberOfDates; i++)
{
var print = RandomDay().ToShortDateString().ToString();
dates += print + "\n";
}
LblDate.Text = dates;
}
嘗試'Environment.NewLine',而不是' 「\ n」'' – Fruchtzwerg
「\ r \ n」',CR + LF – Gusman
使用用於這種操作的StringBuilder,並在循環後轉換爲toString –