Exemple #1
0
        static void Main(string[] args)
        {
            Program p1 = new Program();
            Int32 intBoxed = 10, unboxed;
            //boxing
            Object obj = (Object)intBoxed;
            //unboxing
            try
            {
                Int16 newint = (Int16)obj;
            }
            catch (InvalidCastException ice)
            {
                Console.WriteLine(ice.Message);
            }
            finally
            {
                Int32 newint = (Int32)obj;
                unboxed = newint;
            }
            //Int32 newint = (Int32)obj;
            Console.WriteLine(unboxed);
            p1.WorkingWithArrayList();
            p1.WorkingWithQueue();
            p1.WorkingWithSortedList();
            p1.WorkingWithStack();
            p1.WorkingWithGenerics();
            p1.GenericListDemo();
            p1.GenericStack();
            Demo d1 = new Demo();
            int x = 10, y = 20;
            d1.Swap<Int32>(ref x, ref y);
            Product product1 = new Product(0001, "book", 3.45);
            Product product2 = new Product(0002, "file", 2.13);
            d1.Swap<Product>(ref product1, ref product2);
            //d1.Swap(ref product1, ref product2); //not a standard approach, always specify Type Parameters

            GenericStructure<Int32> myStruct = new GenericStructure<int>(10, 25);
            //myStruct.Reset();
            Console.WriteLine(myStruct);

            TypeParameterConstraints<SatisfyingConstraints> scObj = new TypeParameterConstraints<SatisfyingConstraints>();
            scObj.Show(new SatisfyingConstraints(34.678));

            FinalGenericDerivedClass<Product, Employee> objFGDC = new FinalGenericDerivedClass<Product, Employee>();
            objFGDC.Show();
            Console.WriteLine(objFGDC);
            Console.ReadLine();
        }