Mr.AwfulAtProgramming Mr.AwfulAtProgramming - 5 months ago 59
C# Question

ArrayList to MessageBox C#

I was just wondering how can I print an entire ArrayList in a MessageBox?
Here is what I currently have:

ArrayList myData = new ArrayList();
...bunch of Strings added to myData...
private void btnDisplayScores_Click(object sender, EventArgs e)
MessageBox.Show(myData); <-----what I need help with


You can try converting an obsolete ArrayList to IEnumerable<Object> and then Join items together:

 MessageBox.Show(string.Join(Environment.NewLine, myData.OfType<Object>()));

A better design is to change ArrayList to List<Object> (or List<String> if myData should have just String items):

 List<Object> myData = new List<Object>();
 MessageBox.Show(string.Join(Environment.NewLine, myData));