6. Virtual and non-virtual functions
Below is a non-virtual function
Plane { TopSpeed() { Jet : Plane { TopSpeed() { Main(= ,plane.TopSpeed());
Because TopSpeed () is a non-virtual function, the above Code will print 300. To solve this problem, we need to declare this method using virtual, and rewrite it with override in the subclass. If Jet () is not set to override, the result will still be 300, observe the following example.
Plane { TopSpeed() { Jet : Plane { TopSpeed() { Main(= ,plane.TopSpeed());
7. Hide inherited members
You can reuse the variable name in the subclass, but the compiler will remind you that the Member of the subclass is "hiding" the variable of the parent class.
Elephant { Weight = AsianElephant : Elephant { Weight = AsianElephant().Weight); }
If you really want to get a new variable, tell the compiler to stop complaining about it by using the "new" modifier (not obfuscated with the "new" operator ).
AsianElephant : Elephant { Weight = ; }
8. Example of heavy-duty operators. Note that multiple operators of blood must be reloaded as a pair, such 〉,〈
TopSpeed() { > one.TopSpeed() > < one.TopSpeed() < TopSpeed() { ToString() { Main(= = , plane >
9. Overload Parameters
During compilation, the declared type parameters are used to call the overload method. Even if the object of "mamal" is of the real Tiger type, the compiler will call the Mammal overload-unless it is converted to a "dynamic" type, in this case, it will call the real object type based on this method.
Main(= Zoo((dynamic) mammal);
10. Example of using the property accessors method. Note the special usage of the set and value variables.
mySpeed = { { mySpeed = Jet() { TopSpeed = Main(= =
11. Output Current Time
DateTime dt =,dt.ToString());
Specify a format: dt. ToString ("yyyy/MM/dd ")
The current independent general format: dt. ToString ("u ")
Output "yyyy '-'mm'-'dd hh': 'mm': 'ss 'Z '"
12. Write several lines of text to the file.
= StreamWriter((streamWriter !=