我有一個2d數組按鈕[5,5]所有藍色...如何隨機生成5個紅色按鈕在數組中...?如何生成一個隨機數......?在c#
int Rows = 5;
int Cols = 5;
Button[] buttons = new Button[Rows * Cols];
int index = 0;
for (int i = 0; i < Rows; i++)
{
for (int j = 0; j < Cols; j++)
{
Button b = new Button();
b.Size = new Size(40, 55);
b.Location = new Point(55 + j * 45, 55 + i * 55);
b.BackColor = Color.Blue;
buttons[index++] = b;
}
}
panel1.Controls.AddRange(buttons);
在這裏你去:https://stackoverflow.com/questions/2706500/how-do-i-generate-a-random-int-number-in-c –
這不是一個二維陣列... – Gusman