All built-in data types support the so-called default constructor. It allows you to create a variable using a new keyword.
There is an impressive amount of subtle errors in this expression.
Firstly, there is no such thing as an “internal” data type; perhaps this term is defined elsewhere in the book?
Secondly, it would be more accurate to say that all types of structures have an open constructor without parameters, called the default constructor. Some types of classes also have ctor open without parameters; if you do not provide any ctor, then the C # compiler automatically generates a public ctor without parameters for you. If you provide ctor, then the C # compiler will not do this for you.
Third, constructors do not create variables . The author combines many related, but different things: the "new" operator, memory manager, constructor and variable, and the created object. Variables are storage locations and are managed by the CLR; they are not created by the "new" operator.
The correct statement is that the “new” statement in the structure causes the CLR variable to be created in the temporary storage pool; this variable is then initialized by the memory manager, and then passed to the constructor for greater initialization. The value created in this way is then copied somewhere else. The "new" statement in the class forces the CLR to create an object in the long-term storage pool, and then pass the reference to this object to the CLR. No "variable" required.
Knocking variables with objects is a very common mistake; it’s helpful to understand the difference.
In C #, strings do not have a public default constructor.
Right.
I assume that due to the immutability of the strings, they have their own default constructor.
Good, but wrong. There is no built-in constructor without parameters in the line.
[auto-property or field of type string] leads to a legitimate accessible string (default is null). It does not use new ones. He performs some kind of magical construction.
This is not true. A null reference is not a constructed object at all. This is the lack of a built object!
You basically say that my empty garage contains a “magically constructed” non-existent car. This is an extremely strange way to look at an empty garage; an empty garage does not contain a car, not a magically constructed non-existent car.
What happens in a StringContainer script?
The containing type contains the field generated by the compiler - a variable - type strings. Suppose the contained type is a structure or class. When storage for a structure or class is initialized by the memory manager, the memory manager writes a null reference to the storage location associated with the variable.
Finally: I suspect that your confusion is due to the fact that you got the default confusion of "default constructor" and "default value for type". For the structure, they are one and the same:
int x = new int();
and
int x = default(int);
both make int initialization zero.
For a class, they do not do the same:
Fruit f = new Fruit();
makes a new reference to fruits and assigns a reference to the variable f, whereas:
Fruit f = default(Fruit);
coincides with
Fruit f = null;
The constructor is not called.