1. Overview
1.1 Nature of classes and interfaces
Classes and interfaces are used to describe the characteristics of things and thus become programmable things. That is, the physical existence of the things expressed as programming available code. class provides something like a standard template that is instantiated into various objects in the program. Analyze how to generalize things that are physically present as classes and their interfaces.
1.1.1 Abstract classes, derived classes, interfaces
A car, for example, is an abstract class. And cars, trains are also abstract class. Cars, SUVs and buses in automobiles are the specific classes.
Cars, trains are
The number of passengers, the type of tyre and the load of the train are characteristic.
Subordinate derived classes may be suitable for different ancestor derived classes
1. Standard syntax for defining classes and interfaces
1.1 Declaring classes and interfaces
Public class MyClass [: mybase][. Imyinterface][,imysecondinterface]
{// Class members.}
1.2 Defining constructors
(1) Default constructor: If undefined, the default constructor is automatically generated
(2) Refactoring function: Multiple refactoring functions can be defined
(3) Execution order of constructors: always start with the most basic class, always call the function before executing
Grammar:
class myclass{ public MyClass () { // Default constructor code. } public MyClass (int. myInt) { // nondefault constructor Code (use S myInt). }}
1.3 Defining a destructor
When garbage collection is performed, the code in the destructor is executed and the resource is freed. When this function is called, the destructor of the base class is also implicitly called, including the Finalize () call in the System.Object root class.
Grammar:
class myclass{ ~myclass () { // destructor body. }}
Including a call to
In the System.Object root class. This
7th WPF C # How to define classes and their interfaces