Detailed object-oriented C #

// function package or the like is to a set of data in one of the units, called class, is commonly referred to as encapsulated object abstract data types,
// significance is to protect the package or prevent inadvertently destroyed our code ,
// encapsulation package member may be variable, but also members of the packaging method,
// step encapsulating member variables:
// Create a class, is the basic unit of object-oriented classes, i.e. .cs file, as a text file placed inside the C # code, the default access modifier class created for internal, hidden display,
// write the constructor, the basic structure of the class is the constructor, each class has a constructor, hidden by default, access modifier must be public, and no need to write any return value, the same method name with the class name,
fill in the information // class member variables declared outside access modifier can not access the private, declared access modifier to public property, Ctrl + R + E,

Original link: https://www.cnblogs.com/qq450867541/p/6108019.html


// inheritance is to establish a relationship of the intersection between the class, so that a new instance of a derived class may inherit the characteristics defined in the existing base class and may also add new features,
@ inheritance characteristics:
// derived class is a group class extension, the derived class can add new members, but can not remove the definition has been inherited members
// inheritance can be passed, if derived from B, C, a, B and from the derivation, then C is not only inherited members declared in B, also inherits the member a declared,
// constructor and destructor are not inherited, in addition to other members can be inherited, the base class member access method determined only derived classes can I access them
// derived classes if you define new members and members inherited the same name, then you can overwrite the inherited members, but it is not removed those members, but can not access these members,
// class defines a virtual method, virtual property and imaginary index indicator, it is possible to override these members of the derived class, so that the class may exhibit polymorphism,
// derived class can inherit from a class, you can take To achieve multiple inheritance,

// executed first when inheriting the parent class constructor, followed by the implementation of the sub-class constructor, and finally execution method,
// in a derived class to access base class members are generally two ways, one is calling base. <Member> method calls the base class, the second class is a parent type conversion,
// base class when the derived class needs to cover, C # modifier is achieved using the new base class members hide,
// sealed class, if not to make any class constraints, meaning that all classes can be inherited, this can lead to abuse inheritance class hierarchy is very large, the relationship between the class and the class will become a mess cause can not understand, so C # provides a sealed class, only plus sealed modifier required before the parent class, the class can not be inherited, a sealing method is also coupled with the sealed modifier prior methods,
// abstract classes and sealing the contrary, it is inherited born, abstract class can not be instantiated, abstract no specific method for executing code, must be rewritten in a non-abstract derived class, that is, any base class does not implement the code, just defined, and an interface that have the same place
// If there is an abstract class method, the class must be declared as an abstract class,
// sometimes do not want to declare a class abstract class, but want to achieve specific method is not implemented in the base class, but want to implement the method by derived classes rewrite can be used when this happens virtual keyword method is declared as virtual methods,
// Note that the method body must declare virtual methods, abstract methods is not required,
// when inheritance, if there is a base class constructor parameters, the subclass constructor must have a constructor argument, otherwise it will error,

Original link: https://www.cnblogs.com/fangyz/p/5271780.html


// polymorphism

Original link:

https://www.cnblogs.com/longteng1991/archive/2013/06/13/3131739.html
https://www.cnblogs.com/zhangkai2237/archive/2012/12/20/2826734.html
https://www.cnblogs.com/binyao/p/4891306.html
https://www.cnblogs.com/loveyue/archive/2009/04/19/1439025.html

Guess you like

Origin www.cnblogs.com/huangxuQaQ/p/11114356.html