'Visual Basic 2010 Publieke Members Benaderen Object Oriented Programming Namespace Example1 Module Client Public Sub Main() Dim product1 As New Product product1.Price = 1000 product1.Tax = 21 ' Console.WriteLine(product1.Tax = 21) Console.WriteLine(product1.GetPriceIncludingTax() = 1210) ' Console.ReadLine() End Sub End Module End Namespace Namespace Example1 Class Product Private m_Price As Decimal Public Property Price() As Decimal Get Price = m_Price End Get Set(ByVal value As Decimal) m_Price = value End Set End Property Private m_Tax As Decimal Public Property Tax() As Decimal Get Tax = m_Tax End Get Set(ByVal value As Decimal) m_Tax = value End Set End Property End Class End Namespace Namespace Example1 Partial Class Product Public Function GetPriceIncludingTax() As Decimal GetPriceIncludingTax = Price * (1 + (Tax / 100)) End Function End Class End Namespace Namespace Example2 Class Product Private m_Price As Decimal Public Property Price() As Decimal Get Price = m_Price End Get Set(ByVal value As Decimal) m_Price = value End Set End Property Private m_Tax As Decimal Public Property Tax() As Decimal Get Tax = m_Tax End Get Set(ByVal value As Decimal) m_Tax = value End Set End Property Public Function GetPriceIncludingTax() As Decimal GetPriceIncludingTax = Price * (1 + (m_Tax / 100)) End Function End Class Module Client Public Sub Main() Dim product1 As New Product product1.Price = 1000 product1.Tax = 21 ' Console.WriteLine(product1.Tax = 21) Console.WriteLine(product1.GetPriceIncludingTax() = 1210) ' Console.ReadLine() End Sub End Module End Namespace Namespace Example3 Class Product Private m_Price As Decimal Public Property Price() As Decimal Get Price = m_Price End Get Set(ByVal value As Decimal) m_Price = value End Set End Property Private m_Tax As Decimal Public Property Tax() As Decimal Get Tax = (m_Tax / Price) * 100 End Get Set(ByVal value As Decimal) m_Tax = Price * (value / 100) End Set End Property End Class End Namespace Namespace Example3 Partial Class Product Public Function GetPriceIncludingTax() As Decimal GetPriceIncludingTax = Price * (1 + (m_Tax / 100)) End Function End Class Module Client Public Sub Main() Dim product1 As New Product product1.Price = 1000 product1.Tax = 21 ' Console.WriteLine(product1.Tax = 21) Console.WriteLine(product1.GetPriceIncludingTax() = 1210) ' Console.ReadLine() End Sub End Module End Namespace Namespace Example4 Class Product Private m_Price As Decimal Public Property Price() As Decimal Get Price = m_Price End Get Set(ByVal value As Decimal) m_Price = value End Set End Property Private m_Tax As Decimal Public Property Tax() As Decimal Get Tax = (m_Tax / Price) * 100 End Get Set(ByVal value As Decimal) m_Tax = Price * (value / 100) End Set End Property Public Function GetPriceIncludingTax() As Decimal GetPriceIncludingTax = Price * (1 + (Tax / 100)) End Function End Class Module Client Public Sub Main() Dim product1 As New Product product1.Price = 1000 product1.Tax = 21 ' Console.WriteLine(product1.Tax = 21) Console.WriteLine(product1.GetPriceIncludingTax() = 1210) ' Console.ReadLine() End Sub End Module End Namespace 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.