// public static GenericDb<string> GenericDb = new GenericDb<string>();

        static void Main(string[] args)
        {
            #region GenericDb
            OrderDb.Insert(new Order()
            {
                Id = 1, Address = "Some street 4", Receiver = "Trajan"
            });
            OrderDb.Insert(new Order()
            {
                Id = 2, Address = "Some street 23", Receiver = "Nikola"
            });
            OrderDb.Insert(new Order()
            {
                Id = 3, Address = "Some street 33", Receiver = "Bob"
            });

            ProductDb.Insert(new Product()
            {
                Id = 1, Description = "Product1", Title = "Product1"
            });
            ProductDb.Insert(new Product()
            {
                Id = 2, Description = "Product2", Title = "Product2"
            });
            ProductDb.Insert(new Product()
            {
                Id = 3, Description = "Product3", Title = "Product3"
            });

            Console.WriteLine("Orders");
            OrderDb.PrintAll();
            Console.WriteLine("Products");
            ProductDb.PrintAll();

            Console.WriteLine("------------ Get By Id From order and product db ----------------");
            Order   order   = OrderDb.GetById(1);
            Product product = ProductDb.GetById(2);
            Console.WriteLine(order.GetInfo());
            Console.WriteLine(product.GetInfo());

            Console.WriteLine("------------ Get By Index From order and product db ----------------");
            Order   order1   = OrderDb.GetByIndex(1);
            Product product1 = ProductDb.GetByIndex(0);
            Console.WriteLine(order1.GetInfo());
            Console.WriteLine(product1.GetInfo());

            Console.WriteLine("------------ Remove item From order and product db ----------------");
            OrderDb.RemoveById(1);
            ProductDb.RemoveById(3);

            Console.WriteLine("Orders");
            OrderDb.PrintAll();
            Console.WriteLine("Products");
            ProductDb.PrintAll();
            #endregion

            Console.Clear();

            List <string> strings = new List <string> {
                "Trajan", "Nikola", "Bob", "Jill"
            };
            List <int> ints = new List <int> {
                1, 2, 3, 4, 5, 6, 7
            };
            List <double> doubles = new List <double> {
                1.1, 1.2, 1.3, 2.1, 2.2, 2.3
            };

            ListHelper helper = new ListHelper();

            helper.GoThroughStrings(strings);
            helper.GetInfoForString(strings);
            Console.WriteLine("===============");
            helper.GoThroughIntegers(ints);
            helper.GetInfoForInteger(ints);
            Console.WriteLine("=============== GENERIC METHODS");
            helper.GoThrough <string>(strings);
            helper.GetInfo(strings); // the compiler will define the type on its own
            Console.WriteLine("===============");
            helper.GoThrough <int>(ints);
            helper.GetInfo <int>(ints);
            Console.WriteLine("===============");
            helper.GoThrough <double>(doubles);
            helper.GetInfo <double>(doubles);
            Console.WriteLine("===============");
            helper.GetInfo <Order>(OrderDb.GetAll());
            helper.GetInfo <Product>(ProductDb.GetAll());
            Console.WriteLine("===============");

            helper.Print <Order>(OrderDb.GetAll());



            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            #region Not Generic Helpers
            NotGenericListHelper NotGeneric = new NotGenericListHelper();
            List <string>        strings    = new List <string>()
            {
                "str1", "str2", "str3"
            };
            List <int> ints = new List <int>()
            {
                5, 22, -18
            };
            List <bool> bools = new List <bool> {
                true, false, true
            };
            NotGeneric.GoThroughStrings(strings);
            NotGeneric.GetInfoForStrings(strings);
            NotGeneric.GoThroughInts(ints);
            NotGeneric.GetInfoForInts(ints);
            #endregion
            #region Generic Helpers
            // For non static methods ( Uncomment only if you remove static from the methods )
            //GenericListHelper<string> genericHelper1 = new GenericListHelper<string>();
            //GenericListHelper<int> genericHelper2 = new GenericListHelper<int>();
            //GenericListHelper<bool> genericHelper3 = new GenericListHelper<bool>();

            //genericHelper1.GoThrough(strings);
            //genericHelper1.GetInfo(strings);

            //genericHelper2.GoThrough(ints);
            //genericHelper2.GetInfo(ints);

            //genericHelper3.GoThrough(bools);
            //genericHelper3.GetInfo(bools);

            // For static methods
            GenericListHelper <string> .GoThrough(strings);

            GenericListHelper <string> .GetInfo(strings);

            GenericListHelper <int> .GoThrough(ints);

            GenericListHelper <int> .GetInfo(ints);

            GenericListHelper <bool> .GoThrough(bools);

            GenericListHelper <bool> .GetInfo(bools);

            #endregion
            #region Generic Classes
            OrderDb.Insert(new Order()
            {
                Id = 1, Address = "Bob street 29", Receiver = "Bob"
            });
            OrderDb.Insert(new Order()
            {
                Id = 2, Address = "Jill street 31", Receiver = "Jill"
            });
            OrderDb.Insert(new Order()
            {
                Id = 3, Address = "Greg street 11", Receiver = "Greg"
            });
            ProductDb.Insert(new Product()
            {
                Id = 1, Description = "For gaming", Title = "Mouse"
            });
            ProductDb.Insert(new Product()
            {
                Id = 2, Description = "Mechanical", Title = "Keyboard"
            });
            ProductDb.Insert(new Product()
            {
                Id = 3, Description = "64GB", Title = "USB"
            });
            Console.WriteLine("Orders:");
            OrderDb.PrintAll();
            Console.WriteLine("Produts:");
            ProductDb.PrintAll();
            Console.WriteLine("-------Get by id 1 from Order and Product-------");
            Console.WriteLine(OrderDb.GetById(1).GetInfo());
            Console.WriteLine(ProductDb.GetById(1).GetInfo());
            Console.WriteLine("-------Get by index 1 from Order and Product-------");
            Console.WriteLine(OrderDb.GetByIndex(1).GetInfo());
            Console.WriteLine(ProductDb.GetByIndex(1).GetInfo());
            Console.WriteLine("-------Remove by id 1 from Order and Product-------");
            OrderDb.RemoveById(1);
            ProductDb.RemoveById(1);
            Console.WriteLine("Orders:");
            OrderDb.PrintAll();
            Console.WriteLine("Products:");
            ProductDb.PrintAll();
            Console.ReadLine();
            #endregion
        }
Exemple #3
0
        static void Main(string[] args)
        {
            #region GenericMetohds
            var listOfStrings = new List <string>()
            {
                "Trajan", "Goce", "Tosho", "Dragan"
            };
            var listOfIntegers = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0
            };
            var listOfDoubles = new List <double>()
            {
                1.1, 2.2, 3.3, 4.4, 5.5, 6.6
            };

            var helper = new ListHelpers();
            //helper.GoThroughStrings(listOfStrings);
            //helper.GetInfoForStrings(listOfStrings);

            //helper.GoThroughIntegers(listOfIntegers);
            //helper.GetInfoForIntegers(listOfIntegers);

            //helper.GoThrough<string>(listOfStrings);
            //helper.GetInfo<string>(listOfStrings);

            //helper.GoThrough(listOfIntegers);
            //helper.GetInfo(listOfIntegers);

            //helper.GoThrough(listOfDoubles);
            //helper.GetInfo(listOfDoubles);
            #endregion

            #region AddDbData
            OrderDb.Insert(new Order()
            {
                Id = 1, Address = "Bob street 29", Receiver = "Bob"
            });
            OrderDb.Insert(new Order()
            {
                Id = 2, Address = "Jill street 31", Receiver = "Jill"
            });
            OrderDb.Insert(new Order()
            {
                Id = 3, Address = "Greg street 11", Receiver = "Greg"
            });
            ProductDb.Insert(new Product()
            {
                Id = 1, Description = "For gaming", Title = "Mouse"
            });
            ProductDb.Insert(new Product()
            {
                Id = 2, Description = "Mechanical", Title = "Keyboard"
            });
            ProductDb.Insert(new Product()
            {
                Id = 3, Description = "64GB", Title = "USB"
            });
            #endregion

            #region GenericDb
            Console.WriteLine("Orders:");
            OrderDb.PrintAll();
            Console.WriteLine("Products:");
            ProductDb.PrintAll();

            Console.WriteLine("-------------- Get By Id From Order and Product Db -------------");
            Order   order   = OrderDb.GetById(1);
            Product product = ProductDb.GetById(1);
            Console.WriteLine(order.GetInfo());
            Console.WriteLine(product.GetInfo());

            Console.WriteLine("-------------- Get by Index From Order and Product Db -------------");
            Order   order1   = OrderDb.GetByIndex(1);
            Product product1 = ProductDb.GetByIndex(1);
            Console.WriteLine(order1.GetInfo());
            Console.WriteLine(product1.GetInfo());

            Console.WriteLine("-------------- Remove item From Order and Product Db -------------");
            OrderDb.RemoveById(2);
            ProductDb.RemoveById(2);

            Console.WriteLine("Orders:");
            OrderDb.PrintAll();
            Console.WriteLine("Products:");
            ProductDb.PrintAll();
            #endregion


            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            GenericDb <Product> products = new GenericDb <Product>();
            GenericDb <Order>   orders   = new GenericDb <Order>();
            GenericDb <User>    users    = new GenericDb <User>();

            Product p1 = new Product
            {
                Id          = 1,
                Title       = "Coca Cola",
                Description = "Drink"
            };

            Product p2 = new Product
            {
                Id          = 2,
                Title       = "Chips",
                Description = "Nice Chips"
            };

            products.Add(p1);
            products.Add(p2);
            //Storage.AddProduct(p1);
            //Storage.AddProduct(p2);

            Order o1 = new Order
            {
                Id       = 1,
                Address  = "Skopje",
                Receiver = "Risto"
            };

            Order o2 = new Order
            {
                Id       = 2,
                Address  = "Krusevo",
                Receiver = "Radmila"
            };

            //Storage.AddOrder(o1);
            //Storage.AddOrder(o2);
            orders.Add(o1);
            orders.Add(o2);

            User u1 = new User
            {
                Id   = 1,
                Name = "Risto"
            };

            User u2 = new User
            {
                Id   = 2,
                Name = "Radmila"
            };

            users.Add(u1);
            users.Add(u2);

            users.PrintAll();
            products.PrintAll();
            orders.PrintAll();

            users.RemoveById(1);
            users.PrintAll();

            Console.WriteLine(orders.GetById(2)?.GetInfo());
            Console.WriteLine(products.GetByIndex(0).GetInfo());
        }
Exemple #5
0
        static void Main(string[] args)
        {
            #region Not generic methods
            NotGenericListHelper listHelper = new NotGenericListHelper();
            List <string>        strings    = new List <string>()
            {
                "str1", "str2", "str3"
            };
            List <int> numbers = new List <int>()
            {
                1, 2, 3, -10
            };

            listHelper.GoThroughStrings(strings);
            listHelper.GoThroughInts(numbers);

            listHelper.GetInfoForStrings(strings);
            listHelper.GetInfoForInts(numbers);

            #endregion

            Console.WriteLine("=================== Using Generics =======================");

            #region Generic methods
            //Methods declared in a class GenericListHelper which is a normal class
            //And the methods are generic and can accept all type of Lists.

            GenercListHelper genericListHelper = new GenercListHelper();
            List <bool>      checkList         = new List <bool>()
            {
                true, false, true, true, true
            };

            genericListHelper.GoThrough(strings);
            genericListHelper.GetInfo(strings);

            genericListHelper.GoThrough(numbers);
            genericListHelper.GetInfo(numbers);

            genericListHelper.GoThrough(checkList);
            genericListHelper.GetInfo(checkList);
            #endregion

            Console.WriteLine("=================== Using Generic class methods =======================");

            #region Generic classes and methods
            //When using a generic class we must instantiate an object of that class
            //if it is a non-static class. If it is a static class we can use it by just type the name
            //and access the method that we want to use. Don't forget to specify the type in the < > breackets

            GenericClassListHelper <string> stringHelper = new GenericClassListHelper <string>();
            GenericClassListHelper <int>    intHelper    = new GenericClassListHelper <int>();

            List <string> names = new List <string>()
            {
                "Martin", "Dejan", "Ivo"
            };

            stringHelper.GoThrough(names);
            stringHelper.GenericProp = "Something but must be string!";

            intHelper.GoThrough(numbers);
            intHelper.GenericProp = 50;

            //Cannot call static method with an instance of the class GenericClassListHelper
            //stringHelper.GetInfo();

            GenericClassListHelper <bool> .GetInfo(checkList);



            #endregion

            Console.WriteLine("=================== Using Generic class with constraint entity =======================");

            #region Generic class with constraint entity

            //Cannot work since int doesn't inherit or implement BaseEntity
            //GenericDb<int> intDb = new GenericDb<int>();


            OrderDb.Insert(new Order()
            {
                Id = 1, Reciever = "Martin", Address = "Test address number 10"
            });
            OrderDb.Insert(new Order()
            {
                Id = 2, Reciever = "Dejan", Address = "Test address number 11"
            });

            ProductDb.Insert(new Product()
            {
                Id = 1, Title = "Lap top", Description = "An amazing lap top!"
            });
            ProductDb.Insert(new Product()
            {
                Id = 2, Title = "Mobile phone", Description = "An amazing mobile phone!"
            });

            Console.WriteLine("Orders:");
            OrderDb.PrintAll();

            Console.WriteLine("Products:");
            ProductDb.PrintAll();


            Console.WriteLine("Get Order and Product by ID");
            Console.WriteLine("Info about the entities:");
            Console.WriteLine(OrderDb.GetById(1).GetInfo());
            Console.WriteLine(ProductDb.GetById(1).GetInfo());


            Console.WriteLine("Get Order and Product by Index");
            Console.WriteLine(OrderDb.GetByIndex(1).GetInfo());
            Console.WriteLine(ProductDb.GetByIndex(1).GetInfo());


            Console.WriteLine("Remove Order and Product by Id");
            OrderDb.RemoveById(1);
            ProductDb.RemoveById(2);

            Console.WriteLine("Check if itmes were removed");
            OrderDb.PrintAll();
            ProductDb.PrintAll();



            #endregion


            Console.ReadLine();
        }