0

I have a Class A that has some protected members that I want my base Class B to access. I also want Class B to be in the namespace under Class A. Is this possible?

Namespace BLL
   Public Class A
      Protected varA As Integer
      Protected varB As String
   End Class
End Namespace

Namespace BLL.A
   Public Class B
      Inherits A
      Public Sub setA()
         varA = 3
         varB = "test"
      End Sub
   End Class
End Namespace

I then want to be able to access Class B like so:

BLL.A.B.setA()

When I do this I am getting an error "'A' is ambiguous in the namespace BLL". What am I doing wrong?

OhlPatrol
  • 127
  • 2
  • 8

1 Answers1

2

A isn't a namespace, it's a class. You'll have to put B inside of class A.

Namespace BLL
    Public Class A
        Protected varA As Integer
        Protected varB As String
    End Class
End Namespace

Namespace BLL
    Partial Public Class A
        Public Class B
            Inherits A
            Public Sub setA()
                varA = 3
                varB = "test"
            End Sub
        End Class
    End Class
End Namespace

Which I do not recommend of doing. The framework rarely have classes inside of class, especially public ones. But, I'm just one random person on the internet :)

If you really want namespace, I would rename class A something like CarBase and put the other classes in a namespace called Car.

the_lotus
  • 12,668
  • 3
  • 36
  • 53
  • Thanks for the help. I guess maybe I need to rethink how I want to structure this. The main thing I am trying to accomplish is having class A be the main class (Car for example) and then access all of it's subclasses like Car.Ford, Car.Chevy, etc. for organization purposes – OhlPatrol Jul 06 '17 at 13:57
  • I would call the base class CarBase or do like the class [HtmlControl](https://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontrol(v=vs.110).aspx) which is inside namespace HtmlControls (with an s). – the_lotus Jul 06 '17 at 14:01