2.2.3.1 declare abstract classes
Abstract class horse
{
Abstract Public void chaseafterbadguys ();
}
When abstract keywords are used for the base class, the editor will prevent this base class from being directly instantiated.
2.2.3.2 define encapsulation class
It is opposite to an abstract class and cannot be used as a base class.
Sealed class horse
{
}
Sub-classes are not allowed. Reliability, commercial purpose, and performance considerations are considered.
2.2.3.3 communication with the base class
C # allow the use of the Base keyword to access the nearest base class member.
The base keyword is valid only within the class-it cannot be called outside the class.
2.2.3.4 comparison of inheritance and ownership
Inheritance is an important tool for simulating practical problems with classes, which is useful in IS-A link modeling. For example:
A cow is a (IS-A) land animal.
However, you should be especially careful when using inheritance for modeling of ownership-HAS-A relationships. For example:
The basketball team has an indoor sports ground (HAS-A.
The house has a (HAS-A) ground.
2.2.4 object base class
All types in C # are actually derived from the object class.
2.2.5 class members
Field, constant, method, constructor, destructor, attribute, operator, time, indexer.
2.2.5.1 Field
Variable? Static readonly
2.2.5.2 constant
The constant is similar to the field, but the constant value can only be specified when it is used. It cannot be changed at ordinary times.
// Static constants (implicitly static)
Public const int compiletimeconstant = 1;
// Dynamic constant
Public static readonly runtimeconstant = 1;
2.2.5.3 Method
The method declaration in C # consists of an accessible level, a return type, a method name, and a parameter list.
Public int getnextrecordid (string tablename)
{
}
Method Parameters
Parameter Modifier
The keyword ref is used to pass parameters through reference, so that the called method can update the parameter value.
Out, Params
Overload Method