Public Class Class1
Private names As List(Of String)
Private _class2 As New Class2
Public Sub AddName(ByVal name As String)
names.Add(name)
_class2.Add()
End Sub
Public ReadOnly Property AddAge(ByVal name As String) As Class2
Get
_class2.index = names.IndexOf(name)
Return _class2
End Get
End Property
Public Sub Clear()
names.Clear()
_class2.Clear()
End Sub
Public Class Class2
Private _age As List(Of Integer)
Protected Friend index As Integer
Public Property Age() As Integer
Get
Return _age(index)
End Get
Set(ByVal value As Integer)
_age(index) = value
End Set
End Property
Public Sub Add()
_age.Add(0)
End Sub
Public Sub Clear()
_age.Clear()
End Sub
End Class
End Class
如何在 class2 上隐藏、Sub Clear 和 Sub Add,以便它们仅在 class1 上可见,例如;
Public Sub Clear()
names.Clear()
_class2.Clear() '<<<<<<<
End Sub
我希望它们在 Sub Main() 上不可见,就像它们在下面一样。
Sub Main()
Dim person As New Class1
person.AddAge("kid").Clear() '<<<<<<
person.AddAge("kid").Add() '<<<<<<
End Sub
如果我设置了受保护的,我的 class1 就无法访问它。如果我设置了受保护的朋友,Sub Main() 仍然可以访问它们。感谢您的帮助和时间。