要是让button的name用数字随机生成,应该是1-16,那么如何使每个数字出现四次,如果让出现的数字用数组存起来,之后的代码该怎么写????
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] result = Enumerable.Range(0, 16).SelectMany(x => Enumerable.Repeat(x, 4)).OrderBy(_ => Guid.NewGuid()).ToArray();
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
Console.Write(result[i * 8 + j] + "\t");
}
Console.WriteLine();
}
}
}
}
先按按键随机分成4组,再在每一组执行 1-16 的随机数。
4 1 1 8 7 10 14 11
5 9 12 14 1 15 2 8
14 10 10 9 3 15 6 5
13 0 11 3 3 1 12 0
8 3 11 13 2 14 7 2
9 12 0 9 6 5 5 8
12 2 4 11 13 15 7 4
0 13 4 7 6 10 15 6
Press any key to continue . . .
将数组对应成图片索引,放入程序就是你的事情了。