C# 如何将字符串打印到数组中

C# 如何将字符串打印到数组中,c#,arrays,C#,Arrays,我只需要在单击“打印”按钮时将这些名称打印到输出标签上。现在,当我单击按钮打印名称时,会弹出三行,上面写着System.String[]。如何打印这些名称而不是System.String[]消息?谢谢 string[] names = new string[] {"Kevin", "Anthony", "Mike", "Allan" }; private void button1_Click(object sender, EventArgs e) { //taverse the arra

我只需要在单击“打印”按钮时将这些名称打印到输出标签上。现在,当我单击按钮打印名称时,会弹出三行,上面写着
System.String[]。
如何打印这些名称而不是
System.String[]
消息?谢谢

string[] names = new string[] {"Kevin", "Anthony", "Mike", "Allan" };
private void button1_Click(object sender, EventArgs e)
{
    //taverse the array and dispalay the scores into the label
    string output = "";
    for(int i=0;i<=names.Length; i++)
    {
        output = output + names + "\n";
    }
    displayLabel.Text = output;
}
string[]names=新字符串[]{“Kevin”、“Anthony”、“Mike”、“Allan”};
私有无效按钮1\u单击(对象发送者,事件参数e)
{
//t翻转数组并将分数显示到标签中
字符串输出=”;

对于(inti=0;i您忘记添加索引

for (int i = 0; i < names.Length; i++){
    output = output + names[i] + "\n";
}
for(int i=0;i
将数组中的字符串元素组合成一个新的带分隔字符的单个字符串

string.Join("\n", names);
试试这个解决方案

for (int i = 0; i <= names.Length-1; i++){
    output = output + names[i] + "\n";
}

for(int i=0;i您可以只使用以下三行代码:

            var names = new string[] { "Kevin", "Anthony", "Mike", "Allan" };
            var output = names.Aggregate("", (current, name) => current + (name + Environment.NewLine));
            displayLabel.Text = output;

您还可以使用+=运算符
输出+=名称[i]+“\n”