Ekim 2007


Asagidaki ornekte for dongusunde 3 parametre vardir. Bunlardan birincisi sayacin baslangic degeridir. Sayacin baslangic degeri x degiskenidir. Baslangic degiskeni x in degeri “0″ sifirdir. Noktali virgul isareti ile ikinci parametreye gecilir. Ikinci parametremiz de bir kosul ifadesidir. Kosul x degeri “10″ ondan kucuk oldugu surecedir. Bu kosul sayesinde degiskenimizin degeri “10″ ondan kucuk oldugu takdirde dongu calisacaktir. Noktali virgul ile ucuncu parametreye gecilir. Ucuncu paremetremiz dongu calistigi takdirde ikinci parametredeki kosulu saglamak amaci ile yapilmasi gereken islemi icerir. Bu islem x degiskenimizin degerinin dongu her calistiginda “1″ bir arttirilacagini berlitmektedir. Asagidaki ornekte bu islem “x++” olarak belirtilmistir. For dongumuzun parametre tanim satirindan sonra “{,}” parantez isaretleri arasina dongu calistigi takdirde yapilmasi gerekenler yazilir. Asagidaki ornekte MessageBox goruntulenerek iceriginde Merhaba metni tanimlanmisti. Bu ornegimizde ekranda “10″ on kez MessageBox goruntulenecektir.

for (int x = 0; x < 10; x++)
{
        MessageBox.Show(”
Merhaba“);
}

Baglamak : string tipindeki degiskenleri birbirine baglamak icin + operatoru kullanilir.

string isim, soyisim;
isim = “Mikail“;
soyisim = “LEKESiZ“;
string
tamisim = isim + ” ” + soyisim;
MessageBox.Show(
tamisim);

Split : string tipindeki degisken icerisindeki ayraclara gore degiskeni boler. Cikan sonuc dizide tutulur. Dizi verilerinde ayrac yer almaz.

string sehirler = “istanbul,ankara,izmir,antalya“;
string[]
sehir;
sehir = sehirler.Split(’ , ‘);
label1.Text = sehir[0];
label2.Text = sehir[1];
label3.Text = sehir[2];
label4.Text = sehir[3];

Insert : string tipindeki degisken degerine belirtilen yerden baslayarak belirtilen degeri ekler.

string x = “http://www..com“;
string
y;
y = x.Insert(11, “mikaillekesiz“);
MessageBox.Show(
y);

Remove : string tipindeki degisken degerini belirtilen yerden itibaren temizler.

string x = “mikail lekesiz“;
x = x.Remove(6, x.Length - 6);
MessageBox.Show(
x);

Karsilastirma operatorleri iki verinin bir biri ile karsilastirilmasini saglarlar. Karsilastirma operatorleri metin karsilastirmalarida yapilabilir. Karsilastima sonucunda true veya false degeri doner.

Kucuk
int x = 10;
int y = 100;
if (x < y)
{
MessageBox.Show(”x degeri y degerinden kucuktur!”);
}

Kucuk esit
int x = 10;
int y = 100;
if (x <= y)
{
MessageBox.Show(”x degeri y degerinden kucuk veya esittir!”);
}

Buyuk
int x = 10;
int y = 100;
if (y > x)
{
MessageBox.Show(”y degeri x degerinden buyuktur!”);
}

Buyuk esit
int x = 10;
int y = 100;
if (y >= x)
{
MessageBox.Show(”y degeri x degerinden buyuk veya esittir!”);
}

Esit
int x = 100;
int y = 100;
if (x == y)
{
MessageBox.Show(”x degeri y degerine esittir!”);
}

Esit degil
int x = 10;
int y = 100;
if (x != y)
{
MessageBox.Show(”x degeri y degerine esit degildir!”);
}

int[,] x = new int[5, 6];
x[0, 0] =
1;
x[0, 1] =
2;
x[0, 2] =
3;
x[0, 3] =
4;
x[0, 4] =
5;
x[0, 5] =
6;
x[1, 0] =
7;
x[1, 1] =
8;
x[1, 2] =
9;
x[1, 3] =
10;
x[1, 4] =
11;
x[1, 5] =
12;
x[2, 0] =
13;
x[2, 1] =
14;
x[2, 2] =
15;
x[2, 3] =
16;
x[2, 4] =
17;
x[2, 5] =
18;
x[3, 0] =
19;
x[3, 1] =
20;
x[3, 2] =
21;
x[3, 3] =
22;
x[3, 4] =
23;
x[3, 5] =
24;
x[4, 0] =
25;
x[4, 1] =
26;
x[4, 2] =
27;
x[4, 3] =
28;
x[4, 4] =
29;
x[4, 5] =
30;

veya

int[,] x = { { 1, 2, 3, 4, 5, 6 }, { 7, 8, 9, 10, 11, 12 }, { 13, 14, 15, 16, 17, 18 }, { 19, 20, 21, 22, 23, 24 }, { 25, 26, 27, 28, 29, 30 } };

Dizi ayni tipteki bir cok veriyi bir arada tutmak icin kullanilabilir. Dizinin  kac eleman icerecegi dizi tanimlarken veya sonda belirtilebilir.

string [] gun = new string[7];
gun[0] = “pazartesi“;
gun[1] = “sali“;
gun[2] = “carsamba“;
gun[3] = “persembe“;
gun[4] = “cuma“;
gun[5] = “cumartesi“;
gun[6] = “pazar“;

veya

string [] gun = {”pazartesi“, “sali“, “carsamba“, “persembe“, “cuma“, “cumartesi“, “pazar“};

« Previous Page