日期:2014-05-18 浏览次数:20727 次
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { List<List<int>> TValues = new List<List<int>>(); List<int> TFirst = GetValue(30, null);//获得30个随机数泛型集合 TValues.Add(TFirst); List<int> TSecond = GetValue(10, TValues);//获得10个随机数泛型集合 TValues.Add(TSecond); List<int> TThird = GetValue(5, TValues);//获得5个随机数泛型集合 Console.WriteLine("30个数:" + GetString(TFirst)); Console.WriteLine("10个数:" + GetString(TSecond)); Console.WriteLine("5个数:" + GetString(TThird)); } private static List<int> GetValue(int count, List<List<int>> TValues) { List<int> TValue = new List<int>(); Random random = new Random(); int i = 0; int value = 0; while (i < count) { bool bExist = false; value = random.Next(1, 5001); if (TValues != null) { foreach (List<int> Ttmp in TValues) { if (Ttmp.Contains(value)) { bExist = true; break; } } } if (!bExist) { if (!TValue.Contains(value)) { TValue.Add(value); i++; } } } return TValue; } private static string GetString(List<int> T) { string back = ""; foreach (int value in T) { if (back == "") back = value.ToString(); else back += "," + value.ToString(); } return back; } } }
------解决方案--------------------
public int getNum(int[] arrNum,int tmp,int minValue,int maxValue,Random ra){
int n=0;
while (n<=arrNum.Length-1)
{
if (arrNum[n]==tmp)
{
tmp=ra.Next(minValue,maxValue);
getNum(arrNum,tmp,minValue,maxValue,ra);
}
n++;
}
return tmp;
}
参考
------解决方案--------------------
using System; class a { public struct infomation { public const string name = "mark"; public const string contry = "china"; } } class b { static void Main() { a aa = new a(); Console.WriteLine("name:{0} contry:{1}",a.infomation.name,a.infomation.contry); Console.ReadLine(); } }