winform问题:关于随机取值的问题,没分了,就这么点了啊
有一个LIST,现在想通过一个button控制,随机取到list里的n个值得,并赋给ListBox.代码应该如何写?谢谢大家了
------解决方案--------------------public partial class Form1 : Form 
     { 
         private List <string>  list= new List <string> (); 
         private Random rnd=new Random(); 
         public Form1() 
         { 
             InitializeComponent(); 
             list.Add( "小张 "); 
             list.Add( "小李 "); 
             list.Add( "小王 "); 
             list.Add( "小孟 "); 
             list.Add( "小许 "); 
         }   
         private void button1_Click(object sender, EventArgs e) 
         { 
             if(list.Count> 0){ 
             int num=rnd.Next(list.Count); 
             listBox1.Items.Add(list[num]); 
             list.RemoveAt(num); 
             } 
         } 
     }