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.

C# Programming Enumerations Difficulty: Medium
Choose an option
  • A
    To define a variable of type enum color in Main(), we should use the statement: color c;
  • B
    enum color being private cannot be used in Main().
  • C
    We must declare enum color as public to use it outside Sample.
  • D
    To define a variable of type enum color in Main(), use Sample.color c;
  • E
    We must declare private enum color outside the class to be used in Main().

Answer

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