user6923913 user6923913 - 1 year ago 205
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;

Answer Source

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

string.Join("\n", names);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download