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
-
ATo define a variable of type enum color in Main(), we should use the statement: color c;
-
Benum color being private cannot be used in Main().
-
CWe must declare enum color as public to use it outside Sample.
-
DTo define a variable of type enum color in Main(), use Sample.color c;
-
EWe 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.