|
上述两种实体结构皆表达了「组合/部分」关系。请再看个例子:
'ex02.bas
Imports System.ComponentModel
Imports System.Drawing
Imports System.WinForms
'----------------
Class Person
Private p_name As String
Private p_age As Integer
Public Sub New(ByVal na As String, ByVal a As Integer)
p_name = na
p_age = a
End Sub
Public Function isEqual(ByVal obj As Person) As Integer
Dim k As Integer = 0
If Me.p_name = obj.p_name Then
k = 1
End If
isEqual = k
End Function
Public Sub Show()
Messagebox.Show(Me.p_name + ", " + str(Me.p_age))
End Sub
End Class
'-------
Public Class Form1
Inherits System.WinForms.Form
Public Sub New()
MyBase.New()
Form1 = Me
'This call is required by the Win Form Designer.
InitializeComponent()
'TODO: Add any initialization after the InitializeComponent()
call
End Sub
'Form overrides dispose to clean up the component list.
Public Overrides Sub Dispose()
MyBase.Dispose()
components.Dispose()
End Sub
#Region " Windows Form Designer generated code "
.........
#End Region
Protected Sub Form1_Click(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim a As New Person("Alvin", 35)
Dim b As New Person("David", 25)
|