"Class.Property" is not accessible in this context because it is 'Private'

2k Views Asked by At

I'm looking access private member of a class in myproject.vb file. My function header in myproject.vb looks like this,

   Public Function MyVbFunction(ByVal objRequest As BookRequest) As Integer
        Try
  For Each book As Book In objRequest.m_Books
                If Myvbfucntion2(book) = 1 Then
                    Return True
                End If 
            Next
End Try
End Function 

Book Request Class has property m_Books as Private of type BookCollection class

 Public Class BookRequest
     Private m_Books As ExamCollection
    '
    '
    '
    End Function 

It is not allowing me to access 'book', showing as m_Books as private member. How can i access m_Books to pass to Myvbfucntion2.

2

There are 2 best solutions below

0
On BEST ANSWER

You could make a public property and use the get and set functions to tie your property to a private member if you wish.

Public Property Books() As BookCollection
    Get
        Return m_Books
    End Get
    Set(ByVal Value As BooksCollection)
        m_Books = Value
    End Set
End Property

Apologies for any code formatting issues. I wrote this on my mobile phone

0
On

The compiler tells you the answer. It can't access m_exams because it is private. So make it public, that will fix the problem:)

Private means it is only accessible from the same class.

Public means it is accessible from anywhere.