这样做有什么区别:
Public Class Class1
Protected Test1 As String
Public Sub New(ByVal test2 As String)
Test1 = test2
End Sub
End Class
Public Class Class2
Inherits Class1
Public Sub New()
MyBase.New("called from class 2")
End Sub
End Class
和这个:
Public Class Class1
Protected Test1 As String
End Class
Public Class Class2
Inherits Class1
Public Sub New()
Test1 = "Called from class 2"
End Sub
End Class
在第一个示例中,超类实例变量在构造函数中初始化。在第二个示例中,超类实例变量在子类中初始化。
我问的原因是因为我试图从子类中做到这一点:
Public Sub New()
MyBase.New( System.Configuration.ConfigurationManager.AppSettings.Item("PurgeFile" & Me.GetType.Name), & _
System.Configuration.ConfigurationManager.AppSettings.Item("PurgeHeader" & Me.GetType.Name) )
End Sub
我收到一个错误:“调用另一个构造函数时对正在构建的对象的引用无效”。