21 Aralık 2013 Cumartesi

C# da Try Catch ile İşlem Yapma

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
int s1, s2;
double ort;
try
{
s1 = Convert.ToInt32(textBox1.Text);
s2 = Convert.ToInt32(textBox2.Text);
if ((s1<0 || s1>100)||(s2<0||s2>100))
{
throw new Exception();
}
ort = (s1 + s2) / 2.0;
label4.Text = ort.ToString();
}
catch (Exception)
{

MessageBox.Show("0-100 arası tam sayı giriniz ");
}
}
}
}

0 yorum :

Yorum Gönder