用foreach遍历 datagridView 指定列所有的内容

clipboard

string s = "";
foreach (DataGridViewRow item in dataGridView1.Rows) {
    s += item.Cells["单词"].FormattedValue + "\n";
}
MessageBox.Show(s);



为什么不用for呢 因foreach快


string s = "";
for (int i = 0; i < dataGridView1.Rows.Count; i++) {
    s += dataGridView1.Rows[i].Cells["单词"].FormattedValue + "\n";
}
MessageBox.Show(s);
posted @ 2020-01-07 16:38  XE2011  阅读(3349)  评论(0编辑  收藏  举报