尝试获得2个骰子以滚动2个不同的数字,但无论我尝试什么,2个数字总是相同的。我无法解决为什么即使在完成所有这些之后,2个数字总是相同的,例如" 6和6" " 2和2"。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
String[] rolldie()
{
int a = 0;
int b = 0;
string first = "";
string second = "";
for (int i=0; i<20; i++)
{
Random rnd = new Random();
int dice = rnd.Next(1, 7);
if (i == 0) { a = dice; }
if (i == 10) { b = dice; }
first = a.ToString();
second = b.ToString();
}
string[] diceword = {first,second};
return diceword;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = rolldie()[0];
textBox2.Text = rolldie()[1];
}
}
}