How do I put the contents of a list in a single MessageBox?

前端 未结 5 1171
陌清茗
陌清茗 2020-12-28 20:19

Basically, I have a list with multiple items in it and I want a single message box to display them all.

The closest I have got is a message box for each item (using

5条回答
  •  悲哀的现实
    2020-12-28 20:50

    You can join everything into a single string with string.Join:

    var message = string.Join(Environment.NewLine, list);
    MessageBox.Show(message);
    

    However, if you don't have access to .NET 4, you don't have that overload that takes an IEnumerable. You will have to fallback on the one that takes an array:

    var message = string.Join(Environment.NewLine, list.ToArray());
    MessageBox.Show(message);
    

提交回复
热议问题