在字符串中嵌入换行符

Embed newlines in a string

protected void Button1_Click(object sender, EventArgs e)
        {
            result.Text = "Hello! Here is your school information:" <br />
            "Full Name: " + fname.Text + " " + mname.Text + " " + lname.Text +
            "Course, Year and Section: " + cour.Text + " " + yr.Text + "" + sec.Text +
            "Address: " + add.Text +
            "Age: " + age.Text +
            "Contact Information: " + num.Text + " / " + email.Text + "";

        }

如何在此处添加换行符?例如;

全名:比尔·盖茨

课程、年份和专业:

就像那个格式

我一般用Environment.NewLine,也可以加字符串“\r\n”或“\n”(视系统而定)。更多here

编辑: 如评论中所述,如果是网页输出,换行的html标签是<br>。但对于 C# 它只是字符串,所以你的代码应该是

protected void Button1_Click(object sender, EventArgs e)
{
    result.Text = "Hello! Here is your school information:" + "<br />" +
    "Full Name: " + fname.Text + " " + mname.Text + " " + lname.Text +
    "Course, Year and Section: " + cour.Text + " " + yr.Text + "" + sec.Text +
    "Address: " + add.Text +
    "Age: " + age.Text +
    "Contact Information: " + num.Text + " / " + email.Text + "";
}