'Visual Basic 2010 Static Binding via MyClass Static Typing en Dynamic Binding Namespace FieldInitialization Module ValuesStore Public Function GetValue(ByVal message As String) As String Console.WriteLine("GetValue : " & message) GetValue = "SomeValue" End Function End Module Class AClass Public Sub New() m_Value2 = ValuesStore.GetValue("m_Value2") End Sub Private m_Value1 As String = ValuesStore.GetValue("m_Value1") Private m_Value2 As String Private m_Value3 As String = ValuesStore.GetValue("m_Value3") End Class Class Example Public Shared Sub Main() Dim someObject As New AClass ' Console.ReadLine() End Sub End Class End Namespace Namespace DynamicBinding Class Class1 Public Sub New() Console.WriteLine(Value()) End Sub Public Overridable Function Value() As String Value = "Class1.Value" End Function End Class Class Class2 : Inherits Class1 Public Sub New() m_Values = New String() {"Class2.Value(0)", _ "Class2.Value(1)", _ "Class2.Value(2)"} End Sub Private m_Values As String() Public Overrides Function Value() As String Value = m_Values(1) End Function End Class Class Example Public Shared Sub Main() Dim object1 As Class1 = New Class1 Dim object2 As Class2 = New Class2 ' Console.ReadLine() End Sub End Class End Namespace Namespace StaticBinding1 Class Class1 Public Sub New() Console.WriteLine(MyClass.Value()) End Sub Public Overridable Function Value() As String Value = "Class1" End Function End Class Class Class2 : Inherits Class1 Public Sub New() m_Values = New String() {"Class2.Value(0)", _ "Class2.Value(1)", _ "Class2.Value(2)"} End Sub Private m_Values As String() Public Overrides Function Value() As String Value = m_Values(1) End Function End Class Class Example Public Shared Sub Main() Dim object1 As Class1 = New Class1 Dim object2 As Class2 = New Class2 ' Console.ReadLine() End Sub End Class End Namespace Namespace StaticBinding2 Class Class1 Public Sub New() Console.WriteLine(getValue()) End Sub Public Overridable Function Value() As String Value = getValue() End Function Private Function getValue() As String getValue = "Class1" End Function End Class Class Class2 : Inherits Class1 Public Sub New() m_Values = New String() {"Class2.Value(0)", _ "Class2.Value(1)", _ "Class2.Value(2)"} End Sub Private m_Values As String() Public Overrides Function Value() As String Value = m_Values(1) End Function End Class Class Example16 Public Shared Sub Main() Dim object1 As Class1 = New Class1 Dim object2 As Class2 = New Class2 ' Console.ReadLine() End Sub End Class End Namespace 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.