murat335
New member
- Katılım
- 10 Eyl 2005
- Mesajlar
- 874
- Reaction score
- 0
- Puanları
- 0
- Yaş
- 43
c# Ders 2
// Örnek 15
using System;
class DegerTipleri
{
static void DegerTipi(int deger)
{
deger=50;
Console.WriteLine(deger);
}
static void Main()
{
int a=10;
Console.WriteLine("a={0}",a);
DegerTipi(a);
Console.WriteLine(a);
Console.ReadLine();
}
}
//Örnek 16
using System;
class RefaransTipleri
{
static void DegerTipi(string[] deger)
{
deger[0]="100";
Console.WriteLine(deger[0]);
}
static void Main()
{
string[] a= {"10","50"};
Console.WriteLine("a={0}",a[0]);
DegerTipi(a);
Console.WriteLine(a[0]);
Console.ReadLine();
}
}
//Örnek 17
using System;
namespace Diziler
{
class ana
{
static void gonder(int []x,int []y,int n )
{
for(int i=n-1; i<x.Length; i++ )
y=x;
}
static void Main()
{
int[] dizi1={32,24,34,43,54};
int[] dizi2= new int[7];
gonder(dizi1,dizi2,3);
for(int i=0; i<dizi2.Length; i++ )
Console.WriteLine("dizi2 [{0}]={1}",i,dizi2);
Console.ReadLine();
}}
}
// Örnek 18
using System;
namespace Diziler
{
class ana
{
static bool yap(int [,]x ,int a,int b )
{
if(a<x.GetLength(0)&& b<x.GetLength(0))
{
int tut;
for(int i=0; i<x.GetLength(1); i++ )
{
tut=x[a,i];
x[a,i]=x[b,i];
x[b,i]=tut;
}
return true;
}
else return false;
}
static void Main()
{
int[,] sayilar =new int[,]{{24,25,35},{66,54,77},{65,76,75},{23,43,55}};
int i,j;
if (yap(sayilar,1,3)) // 1.Durum
for(i=0; i<sayilar.GetLength(0); i++)
{
Console.WriteLine("\n");
for(j=0; j<sayilar.GetLength(1); j++)
Console.Write(" "+sayilar[i,j]);
}
Console.ReadLine();
}
}
}
• Refarans Tipleri
// Örnek 19
using System;
class RefOrnek
{
static void DenemeRef(ref int xx)
{
xx=50;
}
static void Main()
{
int x=10;
DenemeRef(ref x);
Console.Write(x);
Console.ReadLine();
}
}
// Örnek 20
using System;
class RefOrnek
{
static void DenemeRef(out int xx)
{
xx=50;
}
static void Main()
{
int x;
DenemeRef(out x);
Console.Write(x);
Console.ReadLine();
}
}
// Örnek 20
using System;
namespace referans
{
class ana
{
static int topla(int i,int j)
{return i+j;}
static void degistir(ref int x)
{ x=100;}
static void degistir2(out int x )
{x=51;}
static void ekle1(ref int[] diz )
{
for(int i=0; i<diz.Length; i++ )
{
diz=diz+10;
}
}
static void Main()
{
int b=12; int c=20; int y=12;
Console.WriteLine(topla(b,c));
degistir(ref y); Console.WriteLine
;
int[] diziler={12,13,13,14,111};
ekle1(ref diziler);
for(int i=0; i<diziler.Length; i++ )
Console.WriteLine(diziler);
int k; degistir2(out k);
Console.WriteLine(k);
Console.ReadLine();
}}
}
• Metotların Aşırı Yüklenmesi
// Örnek 21
using System;
class MetotYukle
{
static void Metot1(int x)
{
Console.WriteLine("sadece int x metot çağırıldı");
}
static void Metot1(int x,int y)
{
Console.WriteLine("int x ve y metot çağırıldı");
}
static void Metot1(float x,float y)
{
Console.WriteLine(" float x ve y metot çağırıldı");
}
static void Metot1(string x,string y)
{
Console.WriteLine(" string x ve y metot çağırıldı");
}
static void Main()
{
Metot1("deneme","deneme");
Metot1(13,22);
Metot1(14);
Metot1(22f,56f);
// Metot1(33f,"deneme"); hatalıdır böyle bir metot yok.
Console.ReadLine();
}
• Class Oluşturma
// Örnek 22
using System;
namespace sinifornegi
{
class dortgen
{
public int en;
public int boy;
public void tanimla(int a,int b)
{
en=a;
boy=b;
}
public int alan()
{
return en*boy;
}
}
class ana
{
static void Main()
{
dortgen dd=new dortgen();
dd.en=20;
dd.boy=30;Console.WriteLine(dd.alan());
dd.tanimla(12,12); Console.WriteLine(dd.alan());
dortgen yenidd=new dortgen();
Console.WriteLine(yenidd.boy);
yenidd.boy=13;
yenidd.en=16;
Console.WriteLine(yenidd.alan());
Console.ReadLine();
}
}
}
// Örnek 15
using System;
class DegerTipleri
{
static void DegerTipi(int deger)
{
deger=50;
Console.WriteLine(deger);
}
static void Main()
{
int a=10;
Console.WriteLine("a={0}",a);
DegerTipi(a);
Console.WriteLine(a);
Console.ReadLine();
}
}
//Örnek 16
using System;
class RefaransTipleri
{
static void DegerTipi(string[] deger)
{
deger[0]="100";
Console.WriteLine(deger[0]);
}
static void Main()
{
string[] a= {"10","50"};
Console.WriteLine("a={0}",a[0]);
DegerTipi(a);
Console.WriteLine(a[0]);
Console.ReadLine();
}
}
//Örnek 17
using System;
namespace Diziler
{
class ana
{
static void gonder(int []x,int []y,int n )
{
for(int i=n-1; i<x.Length; i++ )
y=x;
}
static void Main()
{
int[] dizi1={32,24,34,43,54};
int[] dizi2= new int[7];
gonder(dizi1,dizi2,3);
for(int i=0; i<dizi2.Length; i++ )
Console.WriteLine("dizi2 [{0}]={1}",i,dizi2);
Console.ReadLine();
}}
}
// Örnek 18
using System;
namespace Diziler
{
class ana
{
static bool yap(int [,]x ,int a,int b )
{
if(a<x.GetLength(0)&& b<x.GetLength(0))
{
int tut;
for(int i=0; i<x.GetLength(1); i++ )
{
tut=x[a,i];
x[a,i]=x[b,i];
x[b,i]=tut;
}
return true;
}
else return false;
}
static void Main()
{
int[,] sayilar =new int[,]{{24,25,35},{66,54,77},{65,76,75},{23,43,55}};
int i,j;
if (yap(sayilar,1,3)) // 1.Durum
for(i=0; i<sayilar.GetLength(0); i++)
{
Console.WriteLine("\n");
for(j=0; j<sayilar.GetLength(1); j++)
Console.Write(" "+sayilar[i,j]);
}
Console.ReadLine();
}
}
}
• Refarans Tipleri
// Örnek 19
using System;
class RefOrnek
{
static void DenemeRef(ref int xx)
{
xx=50;
}
static void Main()
{
int x=10;
DenemeRef(ref x);
Console.Write(x);
Console.ReadLine();
}
}
// Örnek 20
using System;
class RefOrnek
{
static void DenemeRef(out int xx)
{
xx=50;
}
static void Main()
{
int x;
DenemeRef(out x);
Console.Write(x);
Console.ReadLine();
}
}
// Örnek 20
using System;
namespace referans
{
class ana
{
static int topla(int i,int j)
{return i+j;}
static void degistir(ref int x)
{ x=100;}
static void degistir2(out int x )
{x=51;}
static void ekle1(ref int[] diz )
{
for(int i=0; i<diz.Length; i++ )
{
diz=diz+10;
}
}
static void Main()
{
int b=12; int c=20; int y=12;
Console.WriteLine(topla(b,c));
degistir(ref y); Console.WriteLine
int[] diziler={12,13,13,14,111};
ekle1(ref diziler);
for(int i=0; i<diziler.Length; i++ )
Console.WriteLine(diziler);
int k; degistir2(out k);
Console.WriteLine(k);
Console.ReadLine();
}}
}
• Metotların Aşırı Yüklenmesi
// Örnek 21
using System;
class MetotYukle
{
static void Metot1(int x)
{
Console.WriteLine("sadece int x metot çağırıldı");
}
static void Metot1(int x,int y)
{
Console.WriteLine("int x ve y metot çağırıldı");
}
static void Metot1(float x,float y)
{
Console.WriteLine(" float x ve y metot çağırıldı");
}
static void Metot1(string x,string y)
{
Console.WriteLine(" string x ve y metot çağırıldı");
}
static void Main()
{
Metot1("deneme","deneme");
Metot1(13,22);
Metot1(14);
Metot1(22f,56f);
// Metot1(33f,"deneme"); hatalıdır böyle bir metot yok.
Console.ReadLine();
}
• Class Oluşturma
// Örnek 22
using System;
namespace sinifornegi
{
class dortgen
{
public int en;
public int boy;
public void tanimla(int a,int b)
{
en=a;
boy=b;
}
public int alan()
{
return en*boy;
}
}
class ana
{
static void Main()
{
dortgen dd=new dortgen();
dd.en=20;
dd.boy=30;Console.WriteLine(dd.alan());
dd.tanimla(12,12); Console.WriteLine(dd.alan());
dortgen yenidd=new dortgen();
Console.WriteLine(yenidd.boy);
yenidd.boy=13;
yenidd.en=16;
Console.WriteLine(yenidd.alan());
Console.ReadLine();
}
}
}