C# 2
C# kursumuzun 2. dersinin örnekleriyle devam ediyoruz..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int tamsayi = 0;
baslangic:
Console.WriteLine(“merhaba”);
tamsayi++;
if (tamsayi < 10) // dongu kullanımı ama tavsiye edilmez
{
goto baslangic;
}
while (tamsayi < 10) // daha kullanışlı
{
Console.WriteLine(“merve”);
}
// dongulerle dizi alma
int[] sayidizisi;
sayidizisi = new int[10];
int sayici = 0;
while (sayici < 10)
{
Console.WriteLine( sayici.ToString() + “. degeri giriniz”);
sayidizisi[sayici] = Convert.ToInt32(Console.ReadLine());
sayici++;
}
sayici = 0;
while (sayici < 10)
{
Console.WriteLine(sayidizisi[sayici]);
sayici++;
}
// if else ve for yapısının kullanımı
// ve moda göre büyük kücük harf elde edimi
string cumle;
cumle=Console.ReadLine();
for (int sayi = 0; sayi < cumle.Length; sayi++)
{
if (sayi % 2 == 0)
{
Console.WriteLine(cumle.Substring(sayi, 1).ToUpper());// girilen harfi büyük harfe cevirir.
}
else
{
Console.WriteLine(cumle.Substring(sayi, 1).ToLower());// girilen harfi kücük harfe cevirir.
}
}
// kendinden bi sonraki harfi yazması için
for (int sayi = 0; sayi < cumle.Length; sayi++)
{
Console.Write((char)((int)cumle[sayi] + 1));
}
// menu işlemi
string cumle=”";
char secim;
while(true)
{
Console.WriteLine(“yazı okumak içn 1″);
Console.WriteLine(“yazıyı yazdırmak içn 2″);
Console.WriteLine(“çıkış için 0″);
Console.WriteLine(“giriniz”);
secim=Console.ReadLine()[0];
if(secim==’1′)
{
cumle=Console.ReadLine();
}
else if(secim==’2′)
{
Console.WriteLine(cumle);
}
else if(secim==’0′)
{
break;
}
else
{
Console.WriteLine(“yanlış secim”);
}
}
//faktöriyel hesabı
int sayi;
Console.WriteLine(“sayi giriniz”);
sayi = Convert.ToInt32(Console.ReadLine());
int sonuc = 1;
for (int sayici = 1; sayici <= sayi; sayici++)
{
sonuc = sonuc * sayici;
}
Console.WriteLine(sonuc);
}
}
}