C# Programming - Enumerations

Exercise : Enumerations - General Questions
  • Enumerations - General Questions
6.
Which of the following will be the correct output for the C#.NET code snippet given below?
enum color : int
{
    red = -3,
    green,
    blue 
}
Console.Write( (int) color.red + ", "); 
Console.Write( (int) color.green + ", "); 
Console.Write( (int) color.blue );
-3, -2, -1
-3, 0, 1
0, 1, 2
red, green, blue
color.red, color.green, color.blue
Answer: Option
Explanation:
No answer description is available. Let's discuss.

7.
An enum that is declared inside a class, struct, namespace or interface is treated as public.
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.

8.
Which of the following statements is correct about the C#.NET code snippet given below?
enum per
{
    married, 
    unmarried, 
    divorced, 
    spinster
}
per.married = 10; 
Console.WriteLine(per.unmarried);
The program will output a value 11.
The program will output a value 1.
The program will output a value 2.
The program will report an error since an enum element cannot be assigned a value outside the enum declaration.
The enum elements must be declared private.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

9.
Which of the following is the correct output for the C#.NET code snippet given below?
enum color: int
{ 
    red,
    green, 
    blue = 5, 
    cyan,
    magenta = 10, 
    yellow 
}
Console.Write( (int) color.green + ", " ); 
Console.Write( (int) color.yellow );
2, 11
1, 11
2, 6
1, 5
None of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.

10.
An enum can be declared inside a class, struct, namespace or interface.
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.