1, methods.
There are many member variables for C # classes. Fields, properties, methods, enumerations, delegates, events, and so on. Is something that can be written in a class.
See Mr.okey video, Inside said only method is dry practical, method can be understood as data processing plant. I agree with this statement.
Processing plant, is to carry out a series of raw materials processing, output finished products.
And the method if as the data processing plant, as the name implies, he processed the object is the data. Therefore, the method will have the parameter parentheses, can receive the passed data parameters, namely "raw materials", there will be a return value, you can logically process the data to return the result, that is, "finished."
Methods have construction methods and member methods.
The Member method can be understood to be for everyone to work with the data. And the construction method is for the class itself to work. Therefore, there is no need to have a return value. The construction method sets some states for the class itself.
2, modifier.
The modifier I understand is the "scope" of the person who is expressing the modifier.
Fields require modifiers to be decorated, methods, properties, and large to class, all requiring modifiers to be decorated.
Once a field, property, method is present, it is inevitably called. A method that assigns a value, reads its value, and uses it, is called first.
The call will fail if it exceeds the scope of the modification itself.
For example: With private decoration, the scope of the expression is itself, once the caller out of the "own" scope to invoke the private decorated content, the call failed.
With public decoration, the scope of expression is that everyone
One of the interesting sayings here is that protected
Because an object-oriented feature is inheritance. Subclasses can inherit from parent class
C # from Getting started to mastering the fifth edition explains protected.
If the parent class is defined as public, then both subclasses and non-subclasses can access it.
If the parent class is defined as private, then both subclasses and non-subclasses cannot access it. Is there a modification that allows subclasses to be distinguished from non-subclasses?
So there is the protected, once in the parent class with this adornment, then this content only the subclass can be accessed, not the child class cannot access. It is protected.
Protected this concept when I was in the undergraduate, understanding is not in place, after looking at the fifth edition, immediately there is a kind of clairvoyant feeling.
Internal this modifier, similar to private is the same. Represents "own" access. But this is a different range.
Sealed is used to express that a class cannot be inherited. In Java, Final is used to indicate that a class cannot be inherited.
The virtual representation method can be overridden and written in the parent class
Override means that a method is overridden, written in a subclass
extern as an adjective has an outside meaning, is to tell you that there is an extern here, you can go outside to find its realization ps:abstract
3. New
New is an operator.
As an operator, its function is to create an instance of the type, calling the constructor of the type. And you can get the memory address of the new instance and assign the address to the variable that references it.
If you write only new XX (), and you do not assign the address to a reference variable, the garbage collector will delete this creation for a certain amount of time.
New can also invoke the initializer of the instance.
New or a keyword. As a modifier, you can implement a subclass to hide the parent class method, which is not a common use.
A few interesting sayings