user6923913 user6923913 - 1 month ago 10
C# Question

How to print Strings to an array

I need to simply have these names printed to an output label when a "Print" button is clicked. Right Now when I click the button to print the names it pops up 3 lines that say

System.String[].
How do i get these names to print and not the
System.String[]
message? Thanks!

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;
}

Answer

String.Join() will combine string elements from an array into a new, single string with dividing characters.

string.Join("\n", names);
Comments