最佳答案
我是 C # 的新手,我有一些 Java 的基本知识,但是我不能让这些代码正常运行。
它只是一个基本的计算器,但是当我运行 VS2008程序时,它会给我一个错误:
我做了几乎相同的程序,但在 Java 中使用的是 JSwing,它工作得非常完美。
下面是 c # 的形式:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace calculadorac
{
public partial class Form1 : Form
{
int a, b, c;
String resultado;
public Form1()
{
InitializeComponent();
a = Int32.Parse(textBox1.Text);
b = Int32.Parse(textBox2.Text);
}
private void button1_Click(object sender, EventArgs e)
{
add();
result();
}
private void button2_Click(object sender, EventArgs e)
{
substract();
result();
}
private void button3_Click(object sender, EventArgs e)
{
clear();
}
private void add()
{
c = a + b;
resultado = Convert.ToString(c);
}
private void substract()
{
c = a - b;
resultado = Convert.ToString(c);
}
private void result()
{
label1.Text = resultado;
}
private void clear()
{
label1.Text = "";
textBox1.Text = "";
textBox2.Text = "";
}
}
有什么问题吗? 有办法解决吗?
附言: 我也试过
a = Convert.ToInt32(textBox1.text);
b = Convert.ToInt32(textBox2.text);
但没成功。