By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,571 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,571 IT Pros & Developers. It's quick & easy.

public enum in abstract class?

P: n/a
I've got an abstract class (say foo) and I'd like to define an Enum (say
bar) within that class so that I can then refer to foo.bar.<one of the enum
labels> from within other parts of the program. The enum is *public* in
other words.

What I find is that while the compiler allows the enum declaration within
the abstract class, it turns out that the enum type isn't visible from
outside the class. It is visible from within descendant classes, as though
it were "protected" rather than public.

So, is this expected behavior? If so, then why doesn't the compiler complain
about the

public enum foo ...

that occurs within the abstract class? If not expected behavior, is this a
compiler bug?

Finally, given that what I want doesn't work, what's the "best practice"
here? I have an abstract property of the foo type, so descendant types must
provide that property. I want other classes to be able to access this
property; thus they need to be able to reference the type.

Bill
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Bill,

What is the visibility of the abstract class that contains the
enumeration?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bill Cohagan" <co*****@teraXNOSPAMXquest.com> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
I've got an abstract class (say foo) and I'd like to define an Enum (say
bar) within that class so that I can then refer to foo.bar.<one of the
enum
labels> from within other parts of the program. The enum is *public* in
other words.

What I find is that while the compiler allows the enum declaration within
the abstract class, it turns out that the enum type isn't visible from
outside the class. It is visible from within descendant classes, as though
it were "protected" rather than public.

So, is this expected behavior? If so, then why doesn't the compiler
complain
about the

public enum foo ...

that occurs within the abstract class? If not expected behavior, is this a
compiler bug?

Finally, given that what I want doesn't work, what's the "best practice"
here? I have an abstract property of the foo type, so descendant types
must
provide that property. I want other classes to be able to access this
property; thus they need to be able to reference the type.

Bill

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.