Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# MessageBox For All Items In Array

I am trying to iterate through an array of strings and present all of them in a single messagebox. The code I have at the minute is this:

string[] array = {"item1", "item2", "item3"};
foreach(item in array)
{
   MessageBox.Show(item);
}

This obviously brings up a messagebox for each item, is there any way I can show them all at once in a messagebox outside the loop? I will be using \n to separate the items if this is possible, thanks.

like image 583
Bali C Avatar asked Nov 30 '22 07:11

Bali C


1 Answers

You can combine the individual strings from the array into a single string (such as with the string.Join method) and then display the concatenated string:

string toDisplay = string.Join(Environment.NewLine, array); 
MessageBox.Show(toDisplay);
like image 146
Ani Avatar answered Dec 06 '22 09:12

Ani