Class, find the area of the rectangle, use the area of the rectangle
1 using System; 2 using System. collections. generic; 3 using System. linq; 4 using System. text; 5 6 namespace Test09 7 {8 // class MyClass1 9 // {10 // private int width = 0; // defines the int type variable, the length of the rectangle is 11 // private int height = 0; // defines the int type variable, as the Width of the rectangle 12 ///// <summary> 13 //// length 14 //// </summary> 15 // public int Width 16 //{ 17 // get 18 // {19 // return width; 20 //} 21 // set 22 // {23 // width = value; 24 //} 25 //} 26 //// <summary> 27 //// width 28 //// </summary> 29 // public int Height 30 // {31 // get 32 // {33 // return height; 34 //} 35 // set 36 // {37 // height = value; 38 //} 39 //} 40 //} 41 // <summary> 42 // custom class, this class is inherited from MyClass1 43 //// </summary> 44 // class MyClass2: myClass1 45 // {46 //// <summary> 47 //// calculate the rectangular area of 48 //// </summary> 49 ///// <returns> rectangular Area </returns> 50 // public int Area () 51 // {52 // return Width * Height; 53 //} 54 //} 55 // class Program 56 // {57 // static void Main (string [] args) 58 // {59 // MyClass2 myClass2 = new MyClass2 (); 60 // myClass2.Width = 5; 61 // myClass2.Height = 3; 62 // Console. writeLine ("the area of the rectangle is:" + myClass2.Area (); 63 //} 64 //} 65 class Class1 66 {67 private int width = 0; // declare private 68 private int height = 0; 69 public int Width // public 70 {71 get 72 {73 return width; 74} 75 set 76 {77 width = value; 78} 79} 80 public int Height 81 {82 get 83 {84 return height; 85} 86 set 87 {88 height = value; 89} 90} 91} 92 class Class2: class1 93 {94 public int Area () 95 {96 97 return Width * Height; // It is consistent with the read/write variable name and capitalized for external use, lowercase internal 98} 99 100} 101 class Program // the name of the Program is arbitrary. If the name complies with the naming rules, the 102 {103 static void Main (string [] args) 104 {105 Class2 class2 = new Class2 (); // instantiate object 106 // Class1.Width = 1; 107 // Class1.Height = 1; 108 class2.Width = 1; // assign values through subclass, instead of 109 class2.Height = 1 for the parent class; // use uppercase letters for external use, and Use lowercase letters for internal use. Class1 can tell 110 Console. writeLine (class2.Area (); 111 112} 113} 114 115}