473,756 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base class with Protected modifier

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.
Nov 20 '05 #1
12 1560
* "=?Utf-8?B?Q2hyaXM=?=" <an*******@disc ussions.microso ft.com> scripsit:
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 [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:c6******** ****@ID-208219.news.uni-berlin.de...
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

Nov 20 '05 #3
"Chris" <an*******@disc ussions.microso ft.com> schrieb
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

Nov 20 '05 #4
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.
Nov 20 '05 #5
"Chris" <an*******@disc ussions.microso ft.com> schrieb
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?
--
Armin

Nov 20 '05 #6
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 "MustInheri t" 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.
Nov 20 '05 #7
"Chris" <an*******@disc ussions.microso ft.com> schrieb
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 "MustInheri t" 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.BaseCl ass

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

Nov 20 '05 #8
>What do you mean with "see"? If I declare the base class with MustInherit, I
still can write Dim var As Project1.BaseCl ass 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.
Nov 20 '05 #9
"Chris" <an*******@disc ussions.microso ft.com> schrieb
What do you mean with "see"? If I declare the base class with
MustInherit, I
>still can write
> Dim var As Project1.BaseCl ass

> 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()


In this case, you are use the "New" operator. The reason why you don't see
the base cllas if you declare it as "Mustinheri t" 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

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2659
by: Steve | last post by:
Hello, I'm encountering an unexpected behavior when using the "new" modifier in a derived class to hide an inherited base class property. I use "new" intentionally so I can change the Type of the property in the derived class, and I can use the derived class as expected through standard instantiation. The unexpected behavior occurs when I try to set gather the PropertyInfo for the derived class property via Reflection. I get an...
2
2798
by: Yasutaka Ito | last post by:
Hi folks! I have a BaseForm class that inherits System.Windows.Forms.Form. It has a property, whose value I need supplied by the class that inherits it. The BaseForm usees the value supplied into this property in its Load event. So, I gave the BaseForm and the property 'abstract' modifier, and put the implementation of the property in the inherited class; say MyForm. However, when I did this, I no longer can open MyForm in the design...
2
6478
by: Dan Cimpoiesu | last post by:
Hello What does mean when a protected modifier is apllied to a class. I want to inherit a protected class defined in another class, I saw that the microsoft programmers achieved that. But I cannot ( ex.I want to inherit the protected abstract class CollectionForm that is defined in the CollectionEditor class but I don't achieve this). Any suggestions?
8
4678
by: Stanislav Simicek | last post by:
Hello, I've several C++ classes that must be ported to C#. Is there any construction in C# similar to C++: class A : protected B { ... }
7
6625
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
2
1447
by: Andrew Ducker | last post by:
My UserControl base class has an event handling method in it. I want to use this for several controls on a subclass of this base class. Normally, I can just click on the drop-down and the methods that fit the correct signature appear - however ones from the base class don't! If I go in and change the generated code myself, it works - so things are set up correctly - it just doesn't appear in the dropdown. Anyone else encountered this?
19
1977
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works" End Sub End Class
4
1618
by: Water Cooler v2 | last post by:
If I recall correctly, in C++ there was an access specifier that could label a data member of a class as "can be accessed by everyone else EXCEPT the derived class" -- an accurate opposite of "protected". I think I allude to the "friend" modifier in C++, which is different from the C# "friend". Does C# have any such specifier? Is there a method for a child class to "not" inherit some properties off its base class?
8
2595
by: Mayur H Chauhan | last post by:
All, For my knowledge, if I declare Class as follow, then it thows compilation error. Protected Class Book End Class Even same for...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.