Esempio n. 1
0
 public override void Show(Graphics g)
 {
     ShowShape.DrawSelf(g, GetPenByWin(this));
     if (SubWinList != null)
     {
         foreach (var item in SubWinList)
         {
             item.Show(g);
         }
     }
     // ShowShape.Show();
     //throw new NotImplementedException();
 }
Esempio n. 2
0
        public static void Main()
        {
            var gracePeriod = new TimeSpan(1, 0, 0);
            var date        = DateTime.Now;
            var date1       = date.AddDays(-1);
            var date2       = date1 + TimeSpan.Parse("17:00");
            var date3       = date2 - gracePeriod;

            var aList = new ArrayList();

            //Example of Boxing
            for (var i = 1; i <= 10; i++)
            {
                aList.Add(i);
            }

            for (var i = 0; i < aList.Count; i++)
            {
                // Unboxing....
                var iV = (int)aList[i];
                WriteLine($"This is a list {i}={iV}");
            }

            //Better loop but also unboxing in i2
            foreach (var i2 in aList)
            {
                WriteLine($"{i2}");
            }

            //Better Use of Generics
            var bList = new List <int>();

            for (var i = 1; i <= 10; i++)
            {
                bList.Add(i);
                WriteLine($"Added {bList[i-1],-2:D} to bList position {i-1}");
            }


            //Generic LinkedList <T>
            var llList2 = new LinkedList <int>();

            llList2.AddLast(1);
            llList2.AddFirst(100);
            llList2.AddLast(10);

            foreach (var llint in llList2)
            {
                WriteLine($"{llint, -4} Item.");
            }

            var p1 = new Person();
            var p2 = new Person();

            p1.Name = "Dave";
            p2.Name = p1.Name;

            if (p1.CompareTo(p2) == 0)
            {
                p2.Name = "Chrissie";
            }

            /*
             * Covariance with classes
             */

            var s1 = new Shape
            {
                Width  = 101.45,
                Height = 25.25
            };

            WriteLine(s1.ToString());
            var q1 = new Square(s1.Width);

            WriteLine(q1.ToString());

            Shape s2 = s1.CreateSquare(s1.Width);

            WriteLine(s2.ToString());

            var ans = GiveIt("Do It ");

            WriteLine(ans);

            /*
             * Covariance with Generic Interfaces
             */

            IIndex <Square> squares = SquareCollection.GetReSquares();
            IIndex <Shape>  shapes  = squares;

            for (int i = 0; i < shapes.Count; i++)
            {
                WriteLine(shapes[i]);
            }

            var nShapeDisplay = new ShowShape();

            nShapeDisplay.Show(s1);
            IDisplay <Shape> nSqIDisplay = new ShowShape();
            var nBox = new Square(1.111);

            nSqIDisplay.Show(nBox);

            IDisplay <Shape>  iDisplayShape = new ShowShape();
            IDisplay <Square> iDisplaySq    = iDisplayShape;

            iDisplaySq.Show(q1);

            // Generic Struct
            Nullable <int> n;

            n = 1;
            if (n.HasValue)
            {
                WriteLine($"This is good. {n}");
            }

            int?n1 = 0;

            n1 = null;
            var msg = "";

            msg = (n1 == null ? $"n1 is null" : $"n1 is not null!");


            ReadKey();
        }