2
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double SalarioBase = 0, Descontos = 0, Vantagens = 0;
try
{
SalarioBase = Convert.ToDouble(textBox1.Text);
Vantagens = Convert.ToDouble(textBox2.Text);
Descontos = Convert.ToDouble(textBox3.Text);
}
catch
{
MessageBox.Show("Valores Invalidos");
return;
}
textBox4.Text = Convert.ToString (( SalarioBase + Vantagens ) - Descontos);
}
}
What’s the difference between using the if
and the try
The two answers answer the question about
if
andtry..catch
, but I recommend asking about software architecture - has specific tag here in the OS. In the example of your question the intelligence of your application is on the "screen" or view, and that’s not good practice.– Thiago Lunardi