Let's first look at a code, you can directly CP to debug the results of the VB.NET
Namespace Test Public Class Father Friend Shared _x As Integer = 1 Public Sub New () End Sub End Class Public Class Child Inherits Father Public Sub New () End Sub End ClassEnd NamespacePrivate Sub Button1_Click (ByVal sender As System.Object, ByVal e As System . Eventargs) Handles Button1.Click Dim F1 AS New Father Dim C1 AS New Child F1._x = 1 MessageBox.Show ("Father Class' SHared AttribUes X Has Been Modify TO:" F1._X.toString ()) C1 ............................................... ..s "in the end" s shared attribues x HAS BEEN MODIFY TO: " f1._x.tostring ()) End Sub
Here, the Shared property of the parent class will be affected by the subclavab, because the same memory space is accessed, and the msdn library is explained so explanatory.
Shared constructor's share variable of the function initialization type; they are first running in most type members after the program starts execution. The Shared constructor does not overload the instance constructor and cannot be overloaded.
Unlike the example constructor, the Shared constructor has implicit public access, without any parameters, and other constructor cannot be called. Before the first statement in the Shared constructor, the Shared constructor implicitly executes the initialization initialization of the variable initial value setting items of the Shared variable declared in the type. This corresponds to an assignment sequence that is executed immediately after entering the constructor. The variable initial value setting item is performed in the text sequence that appears in the type declaration.
The exact time running the Shared constructor is basically determined by the implementation, but needs to meet the following conditions:
The Shared constructor runs before any instance of the type of creation. The Shared constructor runs before the citation type shared member. The Shared constructor runs before loading any type derived from the type. The Shared constructor does not run more than one after the single program execution process.
Avoid cyclic references in the Shared variable initial value settings because it is often not possible to determine the loading order of classes that contain these references.