string to int32的问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 小学加减
{
public partial class Form1 : Form
{
int count = 0;
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
string temp = count.ToString();
string ab = "你做对了" + temp + "道题";
MessageBox.Show(ab);
}
private void button1_Click(object sender, EventArgs e)
{
int result;
Random r = new Random();
int i = r.Next(0, 20);
int j = r.Next(0, 20);
if (j < 0)
{
j = Math.Abs(j);
string x = Convert.ToString(i);
string y = Convert.ToString(j);
textBox1.Text = x + " - " + y;
}
else
{
string x = i.ToString();
string y = j.ToString();
textBox1.Text = x + " + " + y;
}
//MessageBox.Show(textBox2.Lines[0]);
result = Convert.ToInt32(textBox2.Lines[0]);
if (result == i + j)
{
MessageBox.Show("OK");
count++;
}
textBox2.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
Random r = new Random();
int i = r.Next(0, 20);
int j = r.Next(0, 20);
if (j < 0)
{
j = Math.Abs(j);
string x = Convert.ToString(i);
string y = Convert.ToString(j);
textBox1.Text = x + " - " + y;
}
else
{
string x = i.ToString();
string y = j.ToString();
textBox1.Text = x + " + " + y;
}
}
}
}
红色的代码始终无法执行,请问是为什么?