user6923913 user6923913 - 7 months ago 60
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

How do i get these names to print and not the
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;


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

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