Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I have this two classes.
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
How can I hide ,Sub Clear and Sub Add on class2, so they'll only be visible on
on Class1, like;
'This Sub is on Class1
Public Sub Clear()
    names.Clear()
    _class2.Clear() '<<<<<<<<<<
End Sub
I want they do not be visible on Sub Main(), like they are below.
Sub Main()
    Dim person As New Class1
 
                        'Those Subs (Clear an Add) are on Class2.
    person.AddAge("kid").Clear() '<<<<<<<<<<
    person.AddAge("kid").Add() '<<<<<<<<<<

End Sub
If I put Protected, class1 cannot access it. If I put Protected Friend, Sub Main() can still access them. Thanks for your help and time.
 
[Moved from Solution 1 (removed) — SA:]
 
Used this from other forum:
 
Trust in .NET follows assembly boundaries. If you get two classes in one assembly then there are two programmers that know how to find each other if there's a problem. The only way to get what you want is to put these classes in a separate class library project. Which then lets you use Friend. And whomever writes that Main method doesn't have to be friendly.
Posted 8-Apr-13 14:42pm
faneleo196
Edited 8-Apr-13 17:10pm
(no name)919.4K
v3
Comments
Maciej Los at 11-Apr-13 18:06pm
   
I don't understand what is for class2 (as nested class). Can you explain it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 8 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100