作用:将固定数组的中的值重新排列输出!
static void Main(string[] args)
{
// string[] Arrlist;
//Arrlist =new string[]{"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
// foreach(string i in Arrlist)
// {
// Console.WriteLine(i);
// }
// Console.ReadLine();
string[] strarr = { "1#", "2#", "3#", "4#", "5#", "6#", "7#" };
arrrandom(ref strarr);
foreach(string i in strarr)
{
Console.Write(i+ "//");
}
Console.ReadLine();
}
///
/// 随机排列数组中的数值顺序
/// 技巧:顺次把数组中的数值和数组随机值置换位置
///
/// 被排列的数组strarr
private static void arrrandom(ref string[] strarr)
{
Random ran = new Random();
int k = 0;
string strtmp = "";
int MaxLength = strarr.Length;
for (int i = 0; i < strarr.Length; i++)
{
// k = ran.Next(0, 7);
k = ran.Next(MaxLength);
if (k != i)
{
strtmp = strarr[i];
strarr[i] = strarr[k];
strarr[k] = strtmp;
}
}
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25253744/viewspace-700297/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/25253744/viewspace-700297/