Mr.AwfulAtProgramming
Mr.AwfulAtProgramming

Reputation: 73

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
    }

Upvotes: 3

Views: 1773

Answers (1)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186728

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));

Upvotes: 8

Related Questions