如何在 MessageBox 中获取列表? [英] How to get a list in a MessageBox?

查看:34
本文介绍了如何在 MessageBox 中获取列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在消息框正文中显示 string 列表的内容?

How can I display the contents of a string list in the body of a message box?

这是我目前所拥有的:

List<string> a = new List<string> {}; 
foreach (DataGridViewCell cell in dgvC.SelectedCells) 
{ 
    a.Add(cell.Value.ToString()); 
} 

MessageBox.Show(a);  // doesn't work !?

推荐答案

MessageBox 需要字符串而不是列表

MessageBox requires a string not a list

StringBuilder sb = new StringBuilder();
foreach (DataGridViewCell cell in dgvC.SelectedCells)
{
    sb.AppendLine(cell.Value.ToString()); 
}
MessageBox.Show(sb.ToString());

这篇关于如何在 MessageBox 中获取列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆