runme.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. public class runme
  4. {
  5. static void Main()
  6. {
  7. // ----- Object creation -----
  8. Console.WriteLine("Creating some objects:");
  9. Circle c = new Circle(10);
  10. Console.WriteLine(" Created " + c);
  11. Square s = new Square(10);
  12. Console.WriteLine(" Created " + s);
  13. // ----- Access a static member -----
  14. Console.WriteLine("\nA total of " + Shape.nshapes + " shapes were created");
  15. // ----- Member data access -----
  16. // Set the location of the object
  17. c.x = 20;
  18. c.y = 30;
  19. s.x = -10;
  20. s.y = 5;
  21. Console.WriteLine("\nHere is their current position:");
  22. Console.WriteLine(" Circle = ({0}, {1})", c.x,c.y);
  23. Console.WriteLine(" Square = ({0}, {1})", s.x,s.y);
  24. // ----- Call some methods -----
  25. Console.WriteLine("\nHere are some properties of the shapes:");
  26. List <Shape> shapeList = new List <Shape> { c,s };
  27. foreach(var o in shapeList){
  28. Console.WriteLine(" " + o);
  29. Console.WriteLine(" area = " + o.area());
  30. Console.WriteLine(" perimeter = " + o.perimeter());
  31. }
  32. Console.WriteLine("\nGuess I'll clean up now");
  33. // Note: this invokes the virtual destructor
  34. c.Dispose();
  35. s.Dispose();
  36. s = new Square(10);;
  37. Console.WriteLine(Shape.nshapes + " shapes remain");
  38. Console.WriteLine("Goodbye");
  39. }
  40. }