Exercise: Enumerations

Questions for: Enumerations

Which of the following statements are correct about enum used in C#.NET?
  1. Every enum is derived from an Object class.
  2. Every enum is a value type.
  3. There does not exist a way to print an element of an enum as a string.
  4. Every enum is a reference type.
  5. The default underlying datatype of an enum is int.
A:
1, 2, 5
B:
1, 4
C:
3, 5
D:
2, 3, 4
Answer: A
No answer description is available. Let's discuss.
Which of the following CANNOT be used as an underlying datatype for an enum in C#.NET?
A:
byte
B:
short
C:
float
D:
int
Answer: C
No answer description is available. Let's discuss.
An enum can be declared inside a class, struct, namespace or interface.
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
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 );
A:
2, 11
B:
1, 11
C:
2, 6
D:
1, 5
Answer: B
No answer description is available. Let's discuss.
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);
A:
The program will output a value 11.
B:
The program will output a value 1.
C:
The program will output a value 2.
D:
The program will report an error since an enum element cannot be assigned a value outside the enum declaration.
Answer: D
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz