public enum in abstract class?

B

Bill Cohagan

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
 
N

Nicholas Paldino [.NET/C# MVP]

Bill,

What is the visibility of the abstract class that contains the
enumeration?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top