Try – Catch kullanarak ortalama hesaplama C#


Kod:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void button1_Click(object sender, EventArgs e)
{
int not1, not2, not3;
double ortalama;
try
{
not1 = int.Parse(textBox1.Text);
not2 = int.Parse(textBox2.Text);
not3 = int.Parse(textBox3.Text);
ortalama = (not1 + not2 + not3) / 3;
textBox4.Text = ortalama.ToString();
}
catch (Exception hata)
{


MessageBox.Show("Hata Meydana Geldi \n" + hata.Message, "Dikkat");
}


}


private void button2_Click(object sender, EventArgs e)
{
Close();
}


private void button3_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
}
}
}