Free mag vol1 | Page 133

CHAPTER 2  BUILDING C# APPLICATIONS By way of example, drag a new Class from the Class Designer Toolbox onto your Class Designer. Name this class Car in the resulting dialog box. Now, using the Class Details window, add a public string field named petName (see Figure 2-20). Figure 2-20. Adding a field with the Class Details window If you now look at the C# definition of the Car class, you will see it has been updated accordingly (minus the additional code comments seen below). public class Car { // Public data is typically a bad idea; however, // it keeps this example simple. public string petName; } Now, activate the designer file once again and drag another new Class onto the designer and name it SportsCar. Now, select the Inheritance icon from the Class Designer Toolbox and click the top of the SportsCar icon. Next, click the mouse on top of the Car class icon. If you performed these steps correctly, you have just derived the SportsCar class from Car (see Figure 2-21). Figure 2-21. Visually deriving from an existing class 66