日期:2014-05-18 浏览次数:20779 次
using System; using System.Collections.Generic; public class TestList { public static void Main() { List<int> aa = new List<int>(); for (int i = 0; i <10; i++) { aa.Add(i);// 0,1, 2, 3, 4, 5, 6, 7, 8, 9; } List<int> bb = new List<int>(); Test(aa, bb); foreach(int i in bb) { Console.WriteLine(i); } Console.ReadLine(); } public static void Test(List<int> aa, List<int> bb) { if (aa.Count == 0) return; Random ra = new Random(); int a = ra.Next(aa.Count); bb.Add(aa[a]); for (int i = 0; i < aa.Count; i++) { if (aa[i] == aa[a]) { aa.RemoveAt(i); } } Test(aa, bb); } };