Back to directory
ForProgramPersonnel, it is necessary to know a concept and understand its execution process, which is helpful for writing better and safer programs.
It's not just a day for the ox, but a step-by-step practice that keeps accumulating knowledge.
Today is my "foundation is the top priority"ArticleAnother lecture of the series is also the most basic one.
Let's talk about it from birth to death.
Class 1 Creation
Public class person {
Static person () {}// do not write, there is also an empty by default
Public Person () {}// do not write, there is also an empty by default
Public string name {Get; private set;} // attribute. Write Permission is only available for this class.
}
In this way, a person will generate, note that it will have two constructor methods at the same time, static person () {}and public person () {}, both of which are empty parameters, their names are respectively the Type constructor method and the instance constructor method. We can know from the name that the first method is only public to this class, it is a method that can be accessed by static members in the class. The second public person () is executed after the class is new to an object (instance, therefore, it is called an instance constructor.
The execution sequence is static first, followed by other constructor methods.
Class 2 Declaration and instantiation
Person = new person ();
In this way, a class object named person is created. When it is created, the public person () constructor is first executed.
3. Use class attributes and Methods
Person. Name = "zzl"; this statement is incorrect, because the name attribute of the person object only has write permission for itself.
4. The object is recycled by GC.
GC, a managed item, is responsible for recycling unused objects.
Back to directory