问一个关于ArrayList的问题

winsvr2003 2006-12-27 02:27:50
如果我的arraylist里存放了100个整数
我想用random随机显示其中一个,并且每在button上点一次,这个随机显示的数要从arraylist里去掉,求大家帮忙,应该怎么写.谢谢了
...全文
164 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujia_0421 2006-12-27
  • 打赏
  • 举报
回复
sorry..手误

while->>if

如下:

private void button1_Click(object sender, EventArgs e)
{
if (list.Count > 0)
{
Random rd = new Random();
int n = rd.Next(0, list.Count);
this.textBox1.Text = list[n].ToString();
//移除
list.RemoveAt(n);
}
}
liujia_0421 2006-12-27
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
while (list.Count > 0)
{
Random rd = new Random();
int n = rd.Next(0, list.Count);
this.textBox1.Text = list[n].ToString();
//移除
list.RemoveAt(n);
}
}
贝贝壳壳 2006-12-27
  • 打赏
  • 举报
回复


Random rand=new Random();
int i=rand.Next(list.Count)
num=(int)list[i];
list.RemoveAt(i);




110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧