Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string productName = "Elma";
            double unitPrice   = 15;
            string description = "Amasya elması";

            string[] fruits = new string[] { "Elma", "Karpuz" };

            Product product1 = new Product();

            product1.ProductName = "Elma";
            product1.UnitPrice   = 15;
            product1.Description = "Amasya elması";

            Product product2 = new Product();

            product2.ProductName = "Karpuz";
            product2.UnitPrice   = 80;
            product2.Description = "Diyarbakır karpuzu";

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

            //type-safe -- tip güvenli
            foreach (var product in products)
            {
                Console.WriteLine(product.ProductName);
                Console.WriteLine(product.UnitPrice);
                Console.WriteLine(product.Description);
                Console.WriteLine("--------------------");
            }

            Console.WriteLine("------------Methods---------------");
            //instance - örnek
            //encapsulation

            ProductManager productManager = new ProductManager();

            productManager.Add(product2);
            productManager.Add(product1);

            Console.WriteLine("-----------Second Methods-------");

            //Aşağıdaki şekilde yapıldığında oluşacak olan hatayı göstermek için örnek olarak oluşturduk.
            productManager.Add2("Armut", "Yeşil armut", 12, 10);
            productManager.Add2("Elma", "Yeşil elma", 12, 9);
            productManager.Add2("Karpuz", "Diyarbakır karpuzu", 12, 8);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string urunAdi  = "Elma";
            double fiyat    = 15;
            string aciklama = "Amasya elması";

            string[] meyveler = new string[] { };

            Product product1 = new Product();

            product1.Adi      = "Elma";
            product1.Fiyati   = 15;
            product1.Aciklama = "Amasya elması";

            Product product2 = new Product();

            product2.Adi      = "Karpuz";
            product2.Fiyati   = 80;
            product2.Aciklama = "Diyarbakır Karpuzu";

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

            // type-safe -- tip güvenliği
            foreach (Product product in products)
            {
                Console.WriteLine(product.Adi);
                Console.WriteLine(product.Fiyati);
                Console.WriteLine(product.Aciklama);
                Console.WriteLine("--------------");
            }


            Console.WriteLine("------Methods-----");
            //instance - örnek
            //encapsulation
            ProductManager productManager = new ProductManager();

            productManager.Add(product1);
            productManager.Add(product2);

            productManager.Add2("Armut", "Yeşil Armut", 12, 10);
            productManager.Add2("Elma", "Yeşil Elma", 9, 9);
            productManager.Add2("Karpuz", "Diyarbakır karpuzu", 19, 8);
        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            string Name    = "Elma";
            double Price   = 15;
            string Details = "Amasya elması";

            string[] fruits = { "Elma", "Karpuz" };

            Product product1 = new Product
            {
                Name    = "Elma",
                Price   = 15,
                Details = "Amasya elması"
            };

            Product product2 = new Product
            {
                Name    = "Karpuz",
                Price   = 80,
                Details = "Diyarbakır karpuzu"
            };

            Product[] products = { product1, product2 };


            List <Product> productsList = new List <Product>()
            {
                product1, product2
            };


            //type-safe -- tip güvenli
            foreach (var product in products)
            {
                Console.WriteLine(product.Name);
                Console.WriteLine(product.Price);
                Console.WriteLine(product.Details);
                Console.WriteLine("--------------------");
            }

            Console.WriteLine("------------Metotlar---------------");
            //instance - örnek
            //encapsulation

            ProductManager productsManager = new ProductManager();

            productsManager.Add(product1);
            productsManager.Add(product2);
            /*************/
            productsManager.Add2("Armut", "Yeşil armut", 12, 10);
            productsManager.Add2("Elma", "Yeşil elma", 12, 9);
            productsManager.Add2("Karpuz", "Diyarbakır karpuzu", 12, 8);
            /*************/
            Console.WriteLine("------------AddClassArray---------------");
            productsManager.AddClassArray(products);
            /*************/
            Console.WriteLine("------------AddClassLisst---------------");
            productsManager.AddClassList(productsList);

            Console.ReadLine();
        }