示例#1
0
        static void Main(string[] args)
        {
            //Instance
            Product product1 = new Product();

            product1.ProductName = "Apple";
            product1.UnitPrice   = 10.5;
            product1.Description = "Amasya";

            Product product2 = new Product();

            product2.ProductName = "Watermelon";
            product2.UnitPrice   = 81;
            product2.Description = "Diyarbakır";

            Product product3 = new Product();

            product3.ProductName = "Orange";
            product3.UnitPrice   = 14;
            product3.Description = "Ege";

            Product[] products = new Product[] { product1, product2 };

            //type safe
            foreach (Product product in products)
            {
                Console.WriteLine("Product :" + product.ProductName + " Price :" + product.UnitPrice + " $  Description :" + product.Description);
            }


            Console.WriteLine("------------------Methods---------------------");
            SepetManager sepetManager = new SepetManager();

            sepetManager.Add(product1);
            sepetManager.Add(product2);
            sepetManager.Add(product3);
        }
示例#2
0
        //Don't repeat yourself....  Clean code.. . Best practice

        static void Main(string[] args)
        {
            string urunAdi  = "Elma";
            double fiyati   = 15;
            string aciklama = "Amasya Elması ";

            Urun urun1 = new Urun();

            urun1.Adi      = "Elma";
            urun1.Fiyati   = 15;
            urun1.Aciklama = "Amasya Elması";


            Urun urun2 = new Urun();

            urun2.Adi      = "Karpuz";
            urun2.Fiyati   = 50;
            urun2.Aciklama = "Diyarbakır Karpuzu";

            Urun urun3 = new Urun();

            urun3.Adi       = "Karpuz";
            urun3.Fiyati    = 50;
            urun3.Aciklama  = "Diyarbakır Karpuzu";
            urun3.StokAdedi = 32;


            Urun[] urunler = new Urun[] { urun1, urun2, urun3 };



            // Type safe --- tip güvenliği
            foreach (Urun urun in urunler)
            {
                Console.WriteLine(" Ürün Adı : {0}  Fiyatı .. :{1} Stoğu : {2}", urun.Adi, urun.Fiyati, urun.StokAdedi);
                Console.WriteLine(" -----------------------");
            }


            Console.WriteLine("----------------METHODLAR--------------------------");

            //instance

            //encapsulation


            SepetManager sepetManager = new SepetManager();

            sepetManager.Ekle(urun1);
            sepetManager.Ekle(urun2);
            sepetManager.Ekle(urun3);


            sepetManager.Ekleme_Operasyon("Greyfurt", "Kocaman iri iri", 12.5);

            sepetManager.Ekleme_Operasyon("Hurma", "İnce kabuk", 2.5);

            sepetManager.Ekleme_Operasyon("Ananas", "Ekvator malı", 22);


            Console.ReadLine();
        }