我是一名初學VB.NET程序員,我試圖用兩個成員實現一個類Principal
,這兩個成員是兩個不同類的實例。Visual Basic .NET中的自動調優屬性
由於我學習如何使用事件和委託我想實現一個事件(如果這可能是一個解決我的問題)來更新objeto2._atributoC21
當值分配給objeto1.atributoC11
,然後用總和更新Principal.total
object1
和object2
的所有成員。
這裏是一個非常粗魯的代碼,但使這個例子明確的,因爲這將是可能的:
Public Class Principal
Public objeto1 As ClaseIncluida1
Public objeto2 As ClaseIncluida2
Public total As Integer
End Class
Public Class ClaseIncluida1
Private _atributoC11 As Integer
Public _atributoC12 As Integer
Public Property atributoC11 As Integer
Get
Return _atributoC11
End Get
Set(ByVal value As Integer)
_atributoC11 = value
End Set
End Property
End Class
Public Class ClaseIncluida2
Public _atributoC21 As Integer
Public _atributoC22 As Integer
End Class
我知道如何使用事件和委託以簡單的方式,但是當我試圖做什麼我上面已經描述過,我發現自己陷入死衚衕。
也許事件和代表不適合Principal
類,但在這種情況下,我該如何實現一個合適的解決方案?