Yazılım Nedir?

Yazılım, temelde bilgisayara nasıl çalışacağını söyleyen komutlar ve veriler bütünüdür.

Bilişim Nedir?

Bilişim, bir anlamda “paylaşmak” demektir. Bilgisayar ve yazılımların insanların ihtiyaçlarına göre düzenlendiği uçsuz bucaksız bir platformdur.

Bilgisayar Mühendisliği Nedir?

Bilgisayar mühendisliği, bilgisayar ve bilgisayar tabanlı sistemlerin yazılım ve donanımlarının tasarımı, gerçekleştirimi ve yönetimi ile ilgilenen bir bilim dalıdır.

Mühendislik Nedir?

Mühendis; teknik, matematiksel ve sosyal veriler ışığında insanların kullanımına yönelik yeni sistemler üretme ve geliştirme ile sorumludur.

Bilim ve Teknoloji İlişkisi Nedir?

Teknoloji, bilimsel keşiflerin uygulamalarını sağlarken, bilim teknolojik ilerlemelerin temelini oluşturan bilgiyi sunar.

14 Ekim 2023 Cumartesi

C#'DA DELEGATE (TEMSİLCİ)

 



namespace CSExamples

{

    class Program

    {

        static void Main(string[] args)

        {



            // Delegate (Temsilciler)


            Hesap hesap = Topla;


            int sonuc = hesap(5, 4);


            Console.WriteLine(sonuc);




            Console.ReadLine();

            

        }


        delegate int Hesap(int x, int y);


        static int Topla(int a, int b)

        {

            return a + b;

        }


        static int Cikar(int a, int b)

        {

            return a - b;

        }


        static int Carp(int a, int b)

        {

            return a * b;

        }


        static int Bol(int a, int b)

        {

            if (a > 0 && b > 0)

                {

                return a / b;

            }

            return 0;

        }

    }

}





namespace CSExamples

{

    class Program

    {

        static void Main(string[] args)

        {



            // Delegate (Temsilciler)


            Hesap hesap = Topla;


            int sonuc = hesap(5, 4);


            hesap = Carp;


            Console.WriteLine("Çarp : " + hesap(5,4));





            Console.WriteLine(sonuc);




            Console.ReadLine();

            

        }


        delegate int Hesap(int x, int y);


        static int Topla(int a, int b)

        {

            return a + b;

        }


        static int Cikar(int a, int b)

        {

            return a - b;

        }


        static int Carp(int a, int b)

        {

            return a * b;

        }


        static int Bol(int a, int b)

        {

            if (a > 0 && b > 0)

                {

                return a / b;

            }

            return 0;

        }

    }

}





namespace CSExamples

{

    class Program

    {

        static void Main(string[] args)

        {



            // Delegate (Temsilciler)


            Hesap hesap = new Hesap(Topla);

            Console.WriteLine("Topla : " + hesap(5,4));




            Console.ReadLine();

            

        }


        delegate int Hesap(int x, int y);


        static int Topla(int a, int b)

        {

            return a + b;

        }


        static int Cikar(int a, int b)

        {

            return a - b;

        }


        static int Carp(int a, int b)

        {

            return a * b;

        }


        static int Bol(int a, int b)

        {

            if (a > 0 && b > 0)

                {

                return a / b;

            }

            return 0;

        }

    }

}






namespace CSExamples

{

    class Program

    {

        static void Main(string[] args)

        {



            // Delegate (Temsilciler)


            Hesap hesap = new Hesap(Topla);

            Console.WriteLine("Topla : " + hesap(5,4));

            hesap = new Hesap(Cikar);

            Console.WriteLine("Çıkar : " + hesap(5, 4));


            Console.ReadLine();

            

        }


        delegate int Hesap(int x, int y);


        static int Topla(int a, int b)

        {

            return a + b;

        }


        static int Cikar(int a, int b)

        {

            return a - b;

        }


        static int Carp(int a, int b)

        {

            return a * b;

        }


        static int Bol(int a, int b)

        {

            if (a > 0 && b > 0)

                {

                return a / b;

            }

            return 0;

        }

    }

}






namespace CSExamples

{

    class Program

    {

        static void Main(string[] args)

        {



            // Delegate (Temsilciler)


            Hesap hesap = new Hesap(Topla);

            int sonuc = hesap.Invoke(4, 4);


            Console.WriteLine(sonuc);


            Console.ReadLine();

            

        }


        delegate int Hesap(int x, int y);


        static int Topla(int a, int b)

        {

            return a + b;

        }


        static int Cikar(int a, int b)

        {

            return a - b;

        }


        static int Carp(int a, int b)

        {

            return a * b;

        }


        static int Bol(int a, int b)

        {

            if (a > 0 && b > 0)

                {

                return a / b;

            }

            return 0;

        }

    }

}



GENERIC DELEGATE (JENERİK TEMSİLCİ)



namespace CSExamples

{

    class Program

    {


        delegate void MyGenericDelegate<T>(T args);




        static void Main(string[] args)

        {



            // Delegate (Temsilciler)




            MyGenericDelegate<string> stringDelegate = new MyGenericDelegate<string>(StringTarget);

            stringDelegate("Talo");





            Console.ReadLine();



        

        }


        static void StringTarget(string arg)

        {

            Console.WriteLine("Arg metnini büyüt: " + arg.ToUpper());

        }


        static void IntTarget(int arg)

        {

            Console.WriteLine("++arg : " + ++arg);

        }


    }

}




namespace CSExamples

{

    class Program

    {


        delegate void MyGenericDelegate<T>(T args);




        static void Main(string[] args)

        {



            // Delegate (Temsilciler)




            MyGenericDelegate<int> intDelegate = new MyGenericDelegate<int>(IntTarget);

            intDelegate(6);




            Console.ReadLine();



        

        }


        static void StringTarget(string arg)

        {

            Console.WriteLine("Arg metnini büyüt: " + arg.ToUpper());

        }


        static void IntTarget(int arg)

        {

            Console.WriteLine("++arg : " + ++arg);

        }


    }

}


DELEGATE & EVENT İLİŞKİSİ

Öncelikle bir form uygulaması açıyoruz ve içine load olarak mesaj yüklüyoruz. Form açılırken gelen mesaj dışında ayrıca form alanına çift tıkladığımızda gelmesi için bir mesaj daha yüklüyoruz. Kodlar aşağıdadır.





namespace WindowsFormsApp1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();


            this.Load += Form1_Load;

            this.DoubleClick += Form1_DoubleClick;

        }

        

        private void Form1_DoubleClick(object sender, EventArgs e)

        {

            MessageBox.Show("Merhaba!");

        }


        private void Form1_Load(object sender, EventArgs e)

        {

            MessageBox.Show("Merhaba!");

        }

    }

}







namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {

        delegate int Del(int x);

        delegate void Yaz(string metin);
        public Form1()
        {
            InitializeComponent();

            Button btn = new Button();
            btn.Text = "Tıkla";
            btn.Name = "btnTikla";
            btn.Width = 200;
            btn.Height = 50;
            btn.Left = btn.Width + 5;
            btn.Click += delegate (object sender, EventArgs e)
            {
                string mesaj = (sender as Button).Text;
                MessageBox.Show(mesaj);
            };
            this.Controls.Add(btn);
        }
        
        
    }
}


ACTION

Geriye değer döndürmeyen void metotlar için kullanılır.




namespace CSExamples
{
    class Program
    {

        delegate void MyGenericDelegate<T>(T args);



        static void Main(string[] args)
        {


            // Action

            Action<int, string> action = new Action<int, string>(KullaniciBilgi);
            action(3, "TALO");
            



            Console.ReadLine();


        
        }

        static void KullaniciBilgi(int kullaniciId, string adSoyad)
        {
            Console.WriteLine("Kullanıcı Id : " + kullaniciId);
            Console.WriteLine("Ad Soyad : " + adSoyad);
        }


        static double GetUserAgeAtTime(DateTime birthDate)
        {
            return (DateTime.Now - birthDate).TotalDays;

        }




    }
}

FUNCTION

Geriye değer dönebilen action versiyonudur.




namespace CSExamples
{
    class Program
    {

        delegate void MyGenericDelegate<T>(T args);



        static void Main(string[] args)
        {


            
            // Function

            Func<DateTime, double> func = new Func<DateTime, double>(GetUserAgeAtTime);
            double dateDiff = func(new DateTime(1991, 2, 6));
            Console.WriteLine(dateDiff + " gündür yaşıyorsunuz.");


            Console.ReadLine();


        
        }

        static void KullaniciBilgi(int kullaniciId, string adSoyad)
        {
            Console.WriteLine("Kullanıcı Id : " + kullaniciId);
            Console.WriteLine("Ad Soyad : " + adSoyad);
        }


        static double GetUserAgeAtTime(DateTime birthDate)
        {
            return (DateTime.Now - birthDate).TotalDays;

        }




    }
}
Paylaş:

29 Eylül 2023 Cuma

C#'DA VIRTUAL/OVERRIDE

Aşağıdaki gibi 2 ayrı sınıf oluşturuyoruz ve kodları giriyoruz.



class Muhendis : Calisan_
{
    public string Tur { get; set; }
    public string Departman { get; set; }

    public override double MaasHesapla()
    {
        return base.MaasHesapla() * 4;
    }
}


class Calisan_
{
    public int ID { get; set; }
    public string Ad { get; set; }
    public string Soyad { get; set; }
    public string Unvan { get; set; }

    public virtual double MaasHesapla()
    {
        return 1.300;
    }

    public override string ToString()
    {
        return this.Ad + " " + this.Soyad;
    }

}




class Program
{
    static void Main(string[] args)
    {

        // Virtual / Override

        Calisan_ isci = new Calisan_();
        isci.Ad = "Taylan";
        isci.Soyad = "Akbaba";
        Console.WriteLine(isci.ToString());
        Console.WriteLine("Maaş : " + isci.MaasHesapla());


        Muhendis muhendis = new Muhendis();
        muhendis.Ad = "Pater";
        muhendis.Soyad = "Alba";
        Console.WriteLine(muhendis.ToString());
        Console.WriteLine("Maaş : " + muhendis.MaasHesapla());



        Console.ReadLine();
        
    }
}





Ve çalıştırıyoruz.




Paylaş:

21 Eylül 2023 Perşembe

C#'DA DÖNGÜLER

 FOR DÖNGÜSÜ

for (int i = 0; i <= 7; i++)

Console.WriteLine("TALO");

Console.ReadLine();






int sonuc = 0;

for (int i = 1; i <= 7; i++)

{

sonuc += i;

Console.WriteLine("Sonuç : " + sonuc);

}

Console.ReadLine();




int[] dizi = new int[10];
int i = 0, x = 0;


for (; i < dizi.Length;)
{
x = dizi.Length;
i++;


}
Console.WriteLine(x - i);
Console.WriteLine(x);
Console.WriteLine(i);


Console.ReadLine();






int i = 0;
for (/*dışarıda tanımladık*/; i < 3;/*içeride tanımladık*/)
{
Console.WriteLine("Döngü içi : " + i);
i++;
}
Console.WriteLine("Döngü dışı : " + i);
Console.ReadLine();



for (; ; )
Console.WriteLine("AA");


for (int i = 1; i <= 100; i++)
{
if (i != 3)
{
Console.WriteLine("Değer : " + i);
}
else
{
Console.WriteLine("Hediye kazandınız!");
}
}


for (int i = 20; i >= 0; i--)
{
Console.WriteLine(i);
}
Console.ReadLine();






int bolunebilen = 0, bolunemeyen = 0;
for (int i = 1; i <= 100; i++)
{
if (i % 5 == 0)
{
Console.WriteLine("Beşe bölünebilen : " + i);
bolunebilen++;
}
else if (i % 5 != 0)
{
Console.WriteLine("Beşe bölünemeyen : " + i);
bolunemeyen++;
}
}
Console.WriteLine("Bölünebilen Sayı Toplam : " + bolunebilen);
Console.WriteLine("Bölünemeyen Sayı Toplam : " + bolunemeyen);
Console.ReadLine();





Console.Write("Sayı : ");
int sayi = Convert.ToInt32(Console.ReadLine());




Console.Write("Kaça : ");
int kacaBol = Convert.ToInt32(Console.ReadLine());


int bolunebilen = 0, bolunemeyen = 0;
for (int i = 1; i <= sayi; i++)
{
if (i % kacaBol == 0)
{
Console.WriteLine("Bölünebilen : " + i);
bolunebilen++;
}
else
{
Console.WriteLine("Bölünemeyen : " + i);
bolunemeyen++;
}
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("******************************");
Console.WriteLine(Environment.NewLine);
Console.WriteLine(bolunebilen + " adet bölünebilen sayı bulundu!");
Console.WriteLine(bolunemeyen + " adet bölünemeyen sayı bulundu!");
Console.ReadLine();





WHILE DÖNGÜSÜ

while (true)
{


}
Console.ReadLine();



while (true)
{
Console.WriteLine("Deep I/O");
}
Console.ReadLine();




int i = 0;
while (i <= 7)
{
Console.WriteLine("Deep I/0 : " + i);
i++;
}
Console.ReadLine();





int bolunebilen = 0, bolunemeyen = 0;
int i = 1;
while (i <= 100)
{
if (i % 5 == 0)
{
Console.WriteLine("Beşe bölünebilen : " + i);
}
else if (i % 5 != 0)
{
Console.WriteLine("Beşe bölünemeyen : " + i);
}
i++;
}
Console.WriteLine("Bölünebilen Sayı Toplam : " + bolunebilen);
Console.WriteLine("Bölğnemeyen Sayı Toplam : " + bolunemeyen);
Console.ReadLine();



Console.Write("Sayı : ");
int sayi = Convert.ToInt32(Console.ReadLine());


Console.Write("Kaça : ");
int kacaBol = Convert.ToInt32(Console.ReadLine());


int bolunemeyen = 0, bolunebilen = 0, i = 1;
while (i <= sayi)
{
if (i % kacaBol == 0)
{
Console.WriteLine("Bölünebilen : " + i);
bolunebilen++;
}
else
{
Console.WriteLine("Bölünemeyen : " + i);
bolunemeyen++;
}
i++;
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("******************************");
Console.WriteLine(Environment.NewLine);
Console.WriteLine(bolunebilen + " adet bölünebilen sayı bulundu!");
Console.WriteLine(bolunemeyen + " adet bölünemeyen sayı bulundu!");
Console.ReadLine();





DO WHİLE DÖNGÜSÜ


 do
{
Console.WriteLine("Deep I/O");
}
while (false);




string str;


int counter = 0, lenght = 0;


do
{
Console.Write("Şifre : ");
str = Console.ReadLine();
lenght = str.Length;
counter++;
} while (str != "12345");


Console.WriteLine();
Console.WriteLine("Deneme Sayısı : " + counter);
Console.WriteLine("Şifre Uzunluk : " + lenght);
Console.WriteLine("Döngüden Çıkıldı");
Console.ReadLine();




string mesaj = false ? "Doğru" : "Yanlış";
Console.WriteLine(mesaj);
Console.ReadLine();



int counter = 0;
bool isValid = false;
string message = string.Empty;
string str = string.Empty;
do
{
Console.Write("Şifreyi Girin : ");
str = Console.ReadLine();
if (str == "12345")
{
isValid = true;
}
counter++;
if (counter >= 5)
{
break;
}
}
while (str != "12345");
Console.WriteLine("***************");
message = isValid ? " Başarılı" : " Başarısız";
Console.WriteLine("Giriş" + message);
Console.WriteLine("Parola Deneme Sayısı : " + counter);
Console.WriteLine("***************");
Console.ReadLine();




BREAK VE CONTINUE

for (int i = 0; i <= 10; i++)
{
if (i < 9)
{
continue;
}
Console.WriteLine(i);
}
Console.WriteLine("Döngü Bitti!");
Console.ReadLine();





int sayi = 0;
for (; ; )
{
Console.WriteLine("Bir Sayı Girin :");


sayi = Convert.ToInt32(Console.ReadLine());


if (sayi == 0)
break;


if (sayi == 5)
{
Console.WriteLine("Sayı Değeri 5");
continue;
}
}
Console.WriteLine("Döngü Bitti!");
Console.ReadLine();



FOREACH

int[] dizi = { 1, 2, 3, 4, 62, 32, 12, 12 };
foreach (int sayi in dizi)
{
Console.WriteLine(sayi);
}
Console.ReadLine();



Paylaş:

İSTATİSTİK

KİTAP ÖNERİSİ