Soy nuevo con C#, tengo algunos conocimientos básicos de Java pero no puedo obtener este código para que se ejecute correctamente.La cadena de entrada no estaba en el formato correcto
Es sólo una calculadora básica, pero cuando ejecuto el VS2008 programa me da este error:
lo hice casi el mismo programa, pero en Java utilizando 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 = "";
}
}
Cuál puede ser el problema? ¿Hay alguna manera de resolverlo?
PS: Yo también trató
a = Convert.ToInt32(textBox1.text);
b = Convert.ToInt32(textBox2.text);
y no funcionó.
Normalmente, 'result' no necesita ser inicializado. – yazanpro