Switch Case Kontrol Deyimi

Kontrol edilecek değer tamsayı, string, char veri tipinde olmalıdır.

Switch (değişken)
{
case1 : komutlar;
break;
case2 : komutlar;
break;
default : komutlar;
break;
}

Örn :

int a;
a=convert.ToInt32(textBox1.text);
Switch (a)
{
case1 : this.text=“Bir”; break;
case2 : this.text=“İki”; break;
case3 : this.text=“Üç”; break;
default : this.text=“1-2-3 sayılarını girmediniz”; break;
}

Örn:

char harf;
harf=convert.ToChar(textbox1.text);
switch(harf);
{
case ‘ e ’ :
case ‘ E ’ : Application.Exit();
break;
case ‘ h ’ : Form 2 yeni=new Form2();
yeni.show();
break;
}

Örn :

string metin;
metin=Textbox1.text;
switch (metin)
{
case “Ankara” : this.text=“06” ;
break;
case “Düzce” : this.text=“81” ;
break;
}

tuna

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir