C # Notes for quick learning

Source: Internet
Author: User

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 != 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.