Try – Catch yapısı Örnek C#
[code lang=”csharp”]
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
{
string ad_soyad, baba_adı, tc_nu, okul_nu;
int not1, not2, not3;
double ort;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
tc_nu = Convert.ToString(textBox2.Text);
ad_soyad = Convert.ToString(textBox1.Text);
okul_nu = Convert.ToString(textBox3.Text);
baba_adı = Convert.ToString(textBox4.Text);
if ((tc_nu.Length < 11) || (tc_nu.Length > 11))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("T.C. Kimlik Numarası 11 Haneden Küçük veya Büyük Olamaz", "Dikkat");
}
}
if ((tc_nu == ""))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("T.C. Kimlik Numarası Girilmelidir", "Dikkat");
}
}
if ((ad_soyad == ""))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("Ad,Soyad Alanı Girilmelidir", "Dikkat");
}
}
if ((okul_nu.Length < 1) || (okul_nu.Length > 4))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("Okul Numarası Alanı Boş Bırakılamaz Yada 4 Haneden Fazla Olamaz", "Dikkat");
}
}
if ((not1 < 0) || (not1 > 100) || (not2 < 0) || (not2 > 100) || (not3 < 0) || (not3 > 100))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("Notlar 0’dan Küçük ve 100’den Büyük Olamaz", "Dikkat");
}
}
if ((not1==0)||(not2==0)||(not3==0))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("Not Alanlarını Doldurunuz", "Dikkat");
}
}
ort = (not1 + not2 + not3) / 3;
textBox8.Text = Convert.ToString(ort);
}
}
}
[/code]

merhaba,
c# öğrenmeye yeni başladım. Kodları incelediğim zaman int not1, not2, not3; değişkenlerine nerede değer atandığını bulamadım.
Bu konuda yardım eder misin, lütfen?
srdrcaglae;
eksik olan satır eklendi.