Base class with Protected modifier

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am trying to create a base class with the Protected keyword

Protected MustInherit Class MyBaseClas
..
..
End Clas

And I got an error saying something like the Protected keyword cannot be used

Anyone has any idea

Thanks.
 
* "=?Utf-8?B?Q2hyaXM=?= said:
I am trying to create a base class with the Protected keyword:

Protected MustInherit Class MyBaseClass
...
...
End Class

And I got an error saying something like the Protected keyword cannot be used.

What do you want to archieve by specifying this keyword?!
 
Herfried K. Wagner said:
What do you want to archieve by specifying this keyword?!

It could make sense in the context of nested classes. I've done that a
few times.

To the original poster: Most likely you are looking for the "Friend"
keyword. "Friend" and "Public" are the only two scope modifiers that can
apply to top-level classes.

Jeremy
 
Chris said:
Hi,

I am trying to create a base class with the Protected keyword:

Protected MustInherit Class MyBaseClass
...
...
End Class

And I got an error saying something like the Protected keyword cannot
be used.

Anyone has any idea?

Thanks.

Protected means that the class is only visible in the outer class and the
classes derived from the outer class.

class outerclass
Protected MustInherit Class MyBaseClass
...
...
End Class
end class


If there is no outer class because you put MyBaseClass in a Namespace,
protected is invalid and doesn't make sense.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
I need to put Protected in front of the base class because if left Public, the base class of the current assembly is visible in another assembly. How do I make the base class invisible in another assembly

Thanks for all of your inputs

Thanks
C.
 
Chris said:
I need to put Protected in front of the base class because if left
Public, the base class of the current assembly is visible in another
assembly. How do I make the base class invisible in another
assembly?

?? Which class is in which assembly?
 
Say there are 2 projects: project 1 is a class library with 1 based class and 1 derived class. Project 2 access project 1 and if the base class is public, project 2 can see the base class, which I don't want. By the way, if I put the "MustInherit" keyword in the bass class, project 2 in VB.net won't see the base class. However, if project 2 is created in C#, it can see the base class

Thanks
C.
 
Chris said:
Say there are 2 projects: project 1 is a class library with 1 based
class and 1 derived class. Project 2 access project 1 and if the
base class is public, project 2 can see the base class, which I don't
want.

If the derived class is public the base class must also be public because
the derived class consists of members in the derived class but also of
members in the base class.
By the way, if I put the "MustInherit" keyword in the bass
class, project 2 in VB.net won't see the base class. However, if
project 2 is created in C#, it can see the base class!

What do you mean with "see"? If I declare the base class with MustInherit, I
still can write

Dim var As Project1.BaseClass

without an error within project 2.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
What do you mean with "see"? If I declare the base class with MustInherit, I
still can write
Dim var As Project1.BaseClass
without an error within project 2.

Sorry, what I meant "see" was the IntelliSense inside the IDE. So when I type:

Dim x As New DerivedClass()

then, there's a dropdown list listing all the available classes and other stuff. And the "base class" is inside the list and I don't want this class to be included in the list. I only want the DerivedClass in the list.

Maybe the "base class" is always in the list. Just like in the .NET library, the Object class which is a base class of other classes is always in the dropdown list...

C.
 
Chris said:
Sorry, what I meant "see" was the IntelliSense inside the IDE. So
when I type:

Dim x As New DerivedClass()

In this case, you are use the "New" operator. The reason why you don't see
the base cllas if you declare it as "Mustinherit" is that a Mustinherit
class is not creatable and intellisense doesn't list it after the New
operator.
then, there's a dropdown list listing all the available classes and
other stuff. And the "base class" is inside the list and I don't
want this class to be included in the list. I only want the
DerivedClass in the list.

Why? If you don't want to be able to create a new instance, you can declare
it as Mustinherit. It is not possible to make the base class private in the
assembly. You might hide it for intellisense but you could still create new
instances (without mustinherit).

What you could do is make the base class creatable only within the assembly.
To do this, declare all constructors as Friend. If you currently don't have
a constructor insert one doing Nothing (friend sub new, end sub)
Maybe the "base class" is always in the list. Just like in the .NET
library, the Object class which is a base class of other classes is
always in the dropdown list...


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Armin Zingler said:
In this case, you are use the "New" operator. The reason why you

...are using..
don't see the base cllas if you declare it as "Mustinherit" is that a

...base class..

Something wrong with my keyboard lately...
 
Back
Top