static void Main(string[] args)
        {
            NonGenericListHelper.PrintInts(new List <int> {
                1, 2, 3
            });
            NonGenericListHelper.PrintStrings(new List <string> {
                "hello", "hi"
            });
            NonGenericListHelper.GetInfoInts(new List <int> {
                1, 2, 3
            });

            GenericListHelper <string> .PrintMembers(new List <string> {
                "hello", "hi"
            });

            GenericListHelper <int> .PrintMembers(new List <int> {
                1, 2, 3
            });

            GenericListHelper <int> .GetInfo(new List <int> {
                1, 2, 3
            });

            TwoTypesGenericHelper <int, string> .Print(new Dictionary <int, string>() { { 1, "hello" }, { 2, "hi" } });

            GenericDb <Product> .Insert(new Product()
            {
                Id = 1, Description = "Pizza", Title = "Pizza"
            });

            GenericDb <Product> .Insert(new Product()
            {
                Id = 2, Description = "Apple", Title = "Apple"
            });

            GenericDb <Product> .PrintAll();

            Product product = GenericDb <Product> .GetById(1);

            Console.WriteLine(product.GetInfo());

            GenericDb <Order> .Insert(new Order()
            {
                Id = 1, Address = "Street 1", Receiver = "Receiver 1"
            });

            GenericDb <Order> .Insert(new Order()
            {
                Id = 2, Address = "Street 2", Receiver = "Receiver 2"
            });

            GenericDb <Order> .PrintAll();

            Order order = GenericDb <Order> .GetByIndex(0);

            Console.WriteLine(order.GetInfo());

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Not generic helper testing
            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);

            // Generic method outside of generic class
            Console.WriteLine("HERE ARE THE RESULTS OF THE GENERIC METHOD");
            Console.WriteLine(ReturnTypeString("Hey"));
            Console.WriteLine(ReturnTypeString <int>(23)); // This is also valid
            Console.WriteLine(ReturnTypeString(new List <bool>()
            {
                true, false
            }));


            // Generic methods in generic class
            // non-static calling
            //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);
            GenericListHelper <string> .GoThrough(strings);

            Console.ReadLine();
        }
Пример #3
0
        public static void GenericMethods()
        {
            //GENERIC METHODS

            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
            };

            //non generic helpers
            NotGenericListHelper.GoThroughtStrings(strings);
            NotGenericListHelper.GetInfoForStrings(strings);
            Console.WriteLine("========");

            NotGenericListHelper.GoThroughInts(ints);
            NotGenericListHelper.GetInfoForInts(ints);
            Console.WriteLine("========");
            Console.WriteLine("========");

            //generic helpers
            GenericListHelper.GoThrough <string>(strings);
            GenericListHelper.GetInfoFor <string>(strings);
            Console.WriteLine("========");

            GenericListHelper.GoThrough <int>(ints);
            GenericListHelper.GetInfoFor <int>(ints);
            Console.WriteLine("========");

            GenericListHelper.GoThrough <bool>(bools);
            GenericListHelper.GetInfoFor <bool>(bools);
            Console.WriteLine("========");
        }