C#.NET — working with private enums in classes. Given a private enum declared inside class Sample, determine how it can be accessed in Main() of another class.

Difficulty: Medium

Correct Answer: We must declare enum color as public to use it outside Sample.

Explanation:

Introduction / Context:Access modifiers affect whether an enum inside a class can be used outside it.

Key Rule:A private enum is scoped only to its containing class. To use it externally, it must be declared public.

Final Answer:We must declare enum color as public to use it outside Sample.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion