当我运行它并玩游戏时,每次只生成数字 0。你能帮我弄清楚问题是什么吗?
public partial class MainPage : PhoneApplicationPage
{
int numberguessed;
// Constructor
public MainPage()
{
InitializeComponent();
Random randnum = new Random();
int numberguessed = randnum.Next(0,1000);
}
private void myButton_Click(object sender, RoutedEventArgs e)
{
myTextBlock.Text = " No worries ! Go again .. ";
myTextbox.Text = "";
myTextbox.Focus();
}
private void myButton2_Click(object sender, RoutedEventArgs e)
{
//string sval = myTextbox.Text;
int ival = System.Convert.ToInt32(myTextbox.Text);
if (ival == numberguessed)
myTextBlock.Text = " You won ";
else if (ival < numberguessed)
myTextBlock.Text = "Your guess is too low !";
else if (ival > numberguessed)
myTextBlock.Text = "Your guess is too high !";
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
myTextbox.Focus();
}