Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

namespace Hafta13PersembeA

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

#region Generics
//ITest<int> test = new Test<int>(9);
//test.Ekle(80);
//test.Ekle(9);
//test.Ekle(19);
////test.Ekle("asdas");
//test.EkranaYazdir();

//ITest<string> test2 = new Test<string>("9");


//test2.Ekle("Ali");
//test2.Ekle("Veli");
//test2.Ekle("Selami");
//test2.Ekle("Ayşe");

//test2.EkranaYazdir();

//ITest<Urun> test3 = new Test<Urun>(


// new Urun
// {
// Id = 1,
// UrunAdi = "Asus",
// Fiyat = 1000
// });

//test3.Ekle(new Urun
//{
// Id = 2,
// UrunAdi = "Acer",
// Fiyat = 10000
//});

//test3.Ekle(new Urun
//{
// Id = 3,
// UrunAdi = "HP",
// Fiyat = 50000
//});

//test3.EkranaYazdir();

//IHesaplayici<Deneme> hesaplayici = new Hesaplayici<Deneme>(new


Deneme());
//hesaplayici.HesapYap();

////IHesaplayici<Urun> hesaplayici2 = new Hesaplayici<Urun>(new


Urun());// olmaz
////hesaplayici2.HesapYap();

//IHesaplayici<Deneme2> hesaplayici3 = new Hesaplayici<Deneme2>(new


Deneme2());
//hesaplayici3.HesapYap();
//List<int> yaslar = new List<int>();
//yaslar.Add(10);
//yaslar.Add(90);
//yaslar.Add(79);
//yaslar.Add(29);

//yaslar.Insert(1, 9000);
//yaslar.Remove(90);

//foreach (int yas in yaslar)


//{
// Console.WriteLine(yas);
//}

//List<string> ogrenciler = new List<string>();


//ogrenciler.Add("Ali");
//ogrenciler.Add("Veli");
//ogrenciler.Add("Selami");
//ogrenciler.Add("Ayşe");

#endregion

//var sayi = int.Parse("asd");

//var deger = Console.ReadLine();


//var sayi2 = int.Parse(deger);
//var sonuc = 900 / sayi2;

//Program p = new Program();


//p.EkranaYaz(null);

var deger = Console.ReadLine();


try
{
//var sayi = int.Parse("asd");
var sayi2 = int.Parse(deger);
var sonuc = 900 / sayi2;
}
catch
{
Console.WriteLine("Hata oluştu");
}

try
{
var sayi2 = int.Parse(deger);
var sonuc = 900 / sayi2;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
if (ex.InnerException is not null)
{
Console.WriteLine(ex.InnerException.Message);
Console.WriteLine(ex.InnerException.StackTrace);
}
}

try
{
var sayi2 = int.Parse(deger);
sayi2 = Math.Max(1, sayi2);

var sonuc = 900 / sayi2;


}
catch (FormatException ex)
{
Console.WriteLine("Girilen deger hatalı");
}
catch (DivideByZeroException ex)
{
Console.WriteLine("Sıfıra bölünemez");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

try
{
//Hata olma olasılığı olan kodlar
}
catch (Exception)
{
//Hata olunca çalışacak kodlar
}
finally
{
// hata olsa da olmasa da çalışacak kodlar
}

try
{
var sayi2 = int.Parse(deger);
var sonuc = 900 / sayi2;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
//finally
//{
// Console.WriteLine("Hata olasa da olmasa da çalışır");
//}

Console.WriteLine("Hata olasa da olmasa da çalışır");

Console.WriteLine("********");

Personel personel = new Personel();


try
{
personel.Calis();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

Console.WriteLine("Hello, World!");
}

public void EkranaYaz(Urun urun)


{
//if (urun is not null)
Console.WriteLine(urun.UrunAdi);
}
}

public interface ITest<T>


{
T Model { get; set; }
T GetbyId(int id);

void Ekle(T input);

void EkranaYazdir();
}

public class Test<T> : ITest<T>


{
public T Model { get; set; }
List<T> liste;

public Test(T model)


{
Model = model;

liste = new List<T>();


}

public void Ekle(T input)


{
liste.Add(input);

Console.WriteLine($"Eklenecek değer = {input}");


}

public T GetbyId(int id)


{
throw new NotImplementedException();
}

public void EkranaYazdir()


{
for (int i = 0; i < liste.Count; i++)
{
var eleman = liste[i];
Console.WriteLine(eleman);
}

foreach (var eleman in liste)


{
Console.WriteLine(eleman);
}
}
}

public class Urun


{
public int Id { get; set; }
public string UrunAdi { get; set; }
public decimal Fiyat { get; set; }

//public static void ToString()


//{
// Console.WriteLine($"Id= {Id} ")
//}

public override string ToString()


{
return $"Id= {Id}, Adı= {UrunAdi}, Fiyat={Fiyat}";
}

public void Hesapla()


{
var rnd = new Random();
Console.WriteLine($"Hesaplama sonucu= {rnd.Next(100)}");
}
}

public interface IDeneme


{
void Hesapla();
}

public class Deneme : IDeneme


{
public void Hesapla()
{
var rnd = new Random();
Console.WriteLine($"Hesaplama sonucu= {rnd.Next(100)}");
}
}

public class Deneme2 : IDeneme


{
public void Hesapla()
{
var rnd = new Random();
Console.WriteLine($"Hesaplama sonucu= {rnd.Next(100,900)}");
}
}

public interface IHesaplayici<T> where T : class, IDeneme


{
void HesapYap();
}

public class Hesaplayici<T> : IHesaplayici<T> where T : class, IDeneme


{
private readonly T _model;

public Hesaplayici(T model)


{
_model = model;
}
public void HesapYap()
{
_model.Hesapla();
}
}

public class Personel


{
private readonly int id = 79;

public Personel()
{
id = 9999;
}

public void Calis()


{
// id = 5500;
var sss = id;

try
{
var sayi2 = int.Parse("0");
var sonuc = 900 / sayi2;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw new Exception();
}
finally
{
Console.WriteLine("Hata olasa da olmasa da çalışır");
}

Console.WriteLine("Hata olasa da olmasa da çalışır 2");

}
}

You might also like