Private Shadows does not hide member variable in base class. Can it be done?

Marcus 1 Reputation point
2021-10-30T15:52:23.657+00:00

I have one base class containing several member variables.

I have four derived classes that inherit the base class.

Two of the variables in the base class are not relevant to one of the four derived classes, so I was hoping to make them unavailable in Intellisense by re-declaring them in the derived class with Private Shadows. However, not only can they still be selected, they actually return the value from the base class! I was not expecting this behaviour at all.

Is there any way to hide irrelevant member variables? This doesn't work:

Public Class Foo
  Public member1 As String
  Public member2 As Integer
  Public member3 As New List(Of Rectangle)
End Class

Public Class Bar1
  Inherits Foo
  Private Shadows member2
  ' some code
End Class

'Elsewhere, in another class:
Dim b As New Bar1
Msgbox(b.member2) ' Intellisense let me select it. When run, no error. Msgbox shows 0.
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
{count} votes