本帖最后由 haxyek 于 2013-10-31 10:09 编辑
把姓名和键值对应好,然后进行随机取值,取出来的值显示出来,并且移除这个值,然后再随机取值,周而复始,循环 字典个数次。- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- namespace 点名
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] lists = { "StuA", "StuB", "StuC", "StuD", "StuE", "StuF" };
- var list = new ArrayList();
- foreach (string tmp in lists)
- {
- list.Add(tmp); //在list里装载数组。
- }
- Console.WriteLine("Pass any key to Start");
- Console.ReadKey(true);
- for (int i = 0; i < lists.Length; i++)
- {
- Random r = new Random();
- int Num=r.Next(list.Count);
- Console.WriteLine(list[Num]);
- list.Remove(list[Num]);
- Console.WriteLine("按任意键选择下一个。");
- Console.ReadKey(true);
- }
- Console.WriteLine("pass any key to exit");
- Console.ReadKey(true);
- }
- }
- }
复制代码 |