A reference type contains a value type field that, when initialized by a reference type, is initialized to 0 and Null by default.
The CLR allows constructors to be defined for value types, but calls to constructors must explicitly write code to invoke them.
The CLR does not allow the definition of a parameterless constructor for a value type. You can only define a parameter constructor, and you must assign a value to all the fields in the value type in the constructor, or you will be given an error.
Although there is no parameterless constructor in C #, you can use this syntax to initialize the fields that are inside:
Structtype st = new Structtype ()//Initialize 0 or null for the inner field
So the reference to the definition of a parametric constructor is:
Copy Code code as follows:
public structtype (int x) {//definition of a parameter constructor
this = new Structtype ()//Initializes all fields to 0 or null
m_x = x;//overwrite m_x field with parameter X, m_x has been initialized to 0 by the previous sentence
}