Mr.AwfulAtProgramming Mr.AwfulAtProgramming - 1 year ago 103
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

Answer Source

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));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download