Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            #region upcasting,downcasting,polymorfism
            //Animal shark = new Shark();
            //object eagle = new Eagle();
            //object a = 5;

            ////Eagle eagle2 = eagle as Eagle;

            //if(a is Eagle)
            //{
            //    Eagle eagle2 = (Eagle)a;
            //}
            //else
            //{
            //    Console.WriteLine("Eagle tipinden deyil");
            //}
            #endregion

            //Kelvin kelvin = new Kelvin();
            //kelvin.Degree = 30;
            //Dollar usd = new Dollar { Usd = 30 };
            //Manat azn = (Manat)usd;
            //Console.WriteLine(azn.Azn);

            Manat azn = new Manat {
                Azn = 20
            };
            Manat azn1 = new Manat {
                Azn = 30
            };
            Console.WriteLine(azn1 == azn);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            #region Upcasting,boxing,implicit
            //Shark shark = new Shark();
            //Bird bird = new Eagle();
            //Eagle eagle = new Eagle();
            //Fork fork = new Fork();

            //object o1 = eagle;
            //object a = 5;

            //object[] arr = { shark, a1, eagle, o1, a };
            //Print(eagle);
            //Print(shark);
            //Print(fork);
            #endregion

            #region Downcasting,unboxing,explicit
            //Animal a1 = new Shark();
            //Animal a2 = new Eagle();

            //object[] arr = { 1, "adasf", a1, true, a2 };

            //foreach (var item in arr)
            //{
            //    if (item is Shark shark)
            //    {
            //        shark.VTest();
            //    }
            //}

            //bool isShark = a2 is Shark;
            //Console.WriteLine(isShark);
            //if(a1 is Shark)
            //{
            //    Shark shark = (Shark)a1;
            //}

            //if(a1 is Shark shark)
            //{
            //    Console.WriteLine(shark);
            //}


            //Shark isShark = a1 as Shark;
            //if (isShark != null)
            //{
            //    Console.WriteLine(isShark);
            //}
            #endregion

            #region Casting buildintypes

            //int a = 2100000000;
            //long l = a;
            //Console.WriteLine(l);
            //long l = 3000000000;
            //int i = (int)l;
            //Console.WriteLine(i);
            //double d = 3.2132;
            //int i = (int)d;
            //Console.WriteLine(i);
            #endregion

            #region Implicit,Explicit operators
            Manat  manat  = new Manat(340);
            Dollar dollar = (Dollar)manat;
            Console.WriteLine(dollar.Usd);
            #endregion
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            #region Custom type operators
            //Person p1 = new Person(){ Name="Memmed",Surname="Necefov",Age=29};
            //Person p2 = new Person();
            //p2.Name = "Elman";
            //p2.Surname = "Elibeyov";
            //p2.Age = 18;


            //Test t = new Test { Name="Kamran",Surname="Jabiyev",Age=29};
            //Test t1 = new Test { Name = "ibrahim", Surname = "Nezerov", Age = 29 };

            //Console.WriteLine("x"=="y");
            #endregion

            #region upcasting,downcasting
            //Eagle eagle = new Eagle();
            //int x = 5;
            //upcasting
            //object shark = new Shark();
            //Animal e1 = eagle;
            //object y = x;
            //object a = eagle;

            //downcasting
            //Bird b1 = new Duck();
            //Shark shark = new Shark();
            //object[] animals = { eagle, b1, shark,x};
            //foreach(var animal in animals)
            //{
            //    if (animal is Eagle)
            //    {
            //        Console.WriteLine("Qartaldir");
            //    }
            //    else
            //    {
            //        Console.WriteLine("Her qush qartal deyil");
            //    }
            //}
            //Eagle e1 = (Eagle)b1;


            //downcasting security way-1
            //if((b1 as Eagle) != null)
            //{
            //    Eagle e1 = (Eagle)b1;
            //}
            //else
            //{
            //    Console.WriteLine("Her qush qartal deyil");
            //}

            //downcasting security way-2
            //if (b1 is Eagle)
            //{
            //    Eagle e1 = (Eagle)b1;
            //}
            //else
            //{
            //    Console.WriteLine("Her qush qartal deyil");
            //}
            #endregion

            Dollar usd = new Dollar()
            {
                Usd = 100
            };
            Manat azn = (Manat)usd;
            Console.WriteLine(azn.Azn);
        }