本文介绍了C#foreach循环随机行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
通过DataRows的foreach循环运行时如何选择随机行.
非常感谢您的帮助.
RB
Hello,
How can I select a random row when running through a foreach loop of DataRows.
Thanks so much for the help.
RB
推荐答案
Random rndm = new Random();
DataRow rndm_row;
foreach(DataRow row in tbl.Rows)
{
rndm_row = tbl.Rows[rndm.Next(0,tbl.Rows.Count - 1)];
// Do something with rndm_row
}
出于好奇,您为什么要这么做?
Out of curiousity, why would you want to do that?
这篇关于C#foreach循环随机行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!