Cadena de entrada no tiene el formato correct
Soy nuevo en C #, tengo algunos conocimientos básicos en Java, pero no puedo ejecutar este código correctamente.
Es solo una calculadora básica, pero cuando ejecuto el programa VS2008 me da este error:
Hice casi el mismo programa pero en Java usando JSwing y funcionó perfectamente.
Aquí está la forma de 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 = "";
}
}
¿Cual puede ser el problema? ¿Hay alguna manera de resolverlo?
PS: también probé
a = Convert.ToInt32(textBox1.text);
b = Convert.ToInt32(textBox2.text);
y no funcionó.