C # Learning the package, inheritance, and polymorphism of the IV-bomb

Source: Internet
Author: User

Three main pillars of OOP: (1) Encapsulation (2) Inheritance (3) polymorphism

Encapsulation in C #, here is a description of static classes and properties.

Static class: A static class that cannot be instantiated, is closed, cannot derive a type from it, and does not have a constructor method.

Static classes: Because the global approach is not allowed in C #, sometimes it takes a few tool classes to implement something like mathematical computing, and static classes come in handy.

Properties and their effects: Rokai's interpretation of attributes in Java class is "property:something that holds data". In general, customers want to access the state of an object without using a method, but the designer of the class wants to hide the state of the class in the class member so that the client can access the object's state indirectly through methods. The attribute satisfies these two purposes: (1) Provide the client with simple "member variable" interface (2) and provide the designer with the data hiding of "using method to achieve" OO design.

The properties are written as follows:

1 usingSystem;2 3 classMyClass4 {5      Public intProperty ;6      Public int Property7     {8         Get{return  This. property;}9         Set{ This. property =value;}Ten     } One     Static voidMain (string[] args) A     { -MyClass Object =NewMyClass (); -Object.property =5; the Console.WriteLine (object.property); -     } -}


C # Learning the package, inheritance, and polymorphism of the IV-bomb

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.