public static void Main(string[] args) { // instantiate Point2, Circle2 and Cylinder2 objects Point2 point = new Point2(7, 11); Circle2 circle = new Circle2(22, 8, 3.5); Cylinder2 cylinder = new Cylinder2(10, 10, 3.3, 10); // create empty array of Shape base-class references Shape shape; // shape refers to Circle2 object shape = circle; string output = point.Name + ": " + point + "\n" + circle.Name + ": " + circle + "\n" + cylinder.Name + ": " + cylinder; // display Name, Area and Volume for shape (circle) // polymorphically output += "\n\n" + shape.Name + ": " + shape + "\nArea = " + shape.Area().ToString("F") + "\nVolume = " + shape.Volume().ToString("F"); //shape now refers to Cylinder2 object shape = cylinder; // display Name, Area and Volume for shape (circle) // polymorphically output += "\n\n" + shape.Name + ": " + shape + "\nArea = " + shape.Area().ToString("F") + "\nVolume = " + shape.Volume().ToString("F"); MessageBox.Show(output, "Demonstrating Polymorphism"); }
public DXEventManager3DWrapperSample() { InitializeComponent(); _selectedMaterial = new DiffuseMaterial(Brushes.Red); _unSelectedMaterial = new DiffuseMaterial(Brushes.Blue); LowerBoxVisual3D.SetName("LowerBoxVisual3D"); PassageBoxVisual3D.SetName("PassageBoxVisual3D"); UpperBoxVisual3D.SetName("UpperBoxVisual3D"); MovableVisualParent.SetName("MovableVisualParent"); MovableBoxVisual3D.SetName("MovableBoxVisual3D"); ArrowLineVisual3D.SetName("ArrowLineVisual3D"); Cylinder1.SetName("Cylinder1"); Cylinder2.SetName("Cylinder2"); Cylinder3.SetName("Cylinder3"); TransparentPlaneVisual3D.SetName("TransparentPlaneVisual3D"); this.Loaded += new RoutedEventHandler(DXEventManager3DWrapperSample_Loaded); // IMPORTANT: // It is very important to call Dispose method on DXSceneView after the control is not used any more (see help file for more info) this.Unloaded += (sender, args) => MainDXViewportView.Dispose(); }