Hafta05

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

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 WindowsFormsNesne
{
public partial class Form15 : Form
{
public Form15()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
try
{
int sayi1 = Convert.ToInt16(textBox1.Text);
int sayi2 = Convert.ToInt16(textBox2.Text);
int topla = sayi1 + sayi2;
label1.Text = topla.ToString();
}
catch (Exception)
{
MessageBox.Show("Rakam Giriniz");
}

private void button2_Click(object sender, EventArgs e)


{
try
{
int s1, s2, sonuc;
s1 = Convert.ToInt16(textBox3.Text);
s2 = Convert.ToInt16(textBox4.Text);
sonuc = s1 * s2;
label2.Text = sonuc.ToString();
}
catch (Exception hata)
{
MessageBox.Show(hata.ToString());
}

private void button3_Click(object sender, EventArgs e)


{
try
{
int s1, s2, sonuc;
s1 = Convert.ToInt16(textBox5.Text);
s2 = Convert.ToInt16(textBox6.Text);
sonuc = s1 * s2;
label3.Text = sonuc.ToString();
}
catch (Exception hata)
{
MessageBox.Show(hata.ToString());
}
finally
{
MessageBox.Show("Finally çalıştı");
}
}

private void button4_Click(object sender, EventArgs e)


{
//Foreach(DeğişkenTürü DeğişkenAdı in DiziAdı)
string[] isimler = { "Ahmet", "Mehmet", "Ali", "Ayşe", "Fatma" };
foreach (string isim in isimler)
{
listBox1.Items.Add(isim);
}
}

private void button5_Click(object sender, EventArgs e)


{
int toplam = 0;
int[] sayilar = { 5, 7, 11, 4, 9 };
foreach (int s in sayilar)
{
listBox2.Items.Add(s);
toplam += s;
}
label4.Text = toplam.ToString();
int ortalama = toplam / sayilar.Length;
label5.Text = ortalama.ToString();
}
}
}

You might also like