Enums_Quiz.md - brainchildservices/curriculum GitHub Wiki
- Which among the following cannot be used as a data type for an enum in C#.NET?
a) short
b) double
c) int
d) all of the mentioned
Answer: b
-
What will be the output of the following C# code?
enum days: int {
sunday = -3, Monday, Tuesday
}
Console.WriteLine((int)days.sunday);
Console.WriteLine((int)days.monday);
Console.WriteLine((int)days.tuesday);
a) -3 0 1
b) 0 1 2
c) -3 -2 -1
d) sunday monday tuesday
Answer: c
- Wrong statement about enum used in C#.NET is?
a) An enum can be declared inside a class
b) An object cannot be assigned to an enum variable
c) An enum can be declared outside a class
d) An enum can have Single and Double values
Answer: d
- What will be the output of the following C# code?
enum per
{ a,
b,
c,
d,
}
per.a = 10;
Console.writeline(per.b);
a) 11
b) 1
c) 2
d) compile time error
Answer: d
Explanation: It will report an error since enum element cannot be assigned a value outside the enum declaration.
- What will be the output of the following C# code?
enum color:int
{ red,
green,
blue = 5,
cyan,
pink = 10,
brown
}
console.writeline((int)color.green);
console.writeline((int)color.brown);
a) 2 10
b) 2 11
c) 1 11
d) 1 5
Answer: c
- What will be the output of the following C# code?
enum letters
{
a,
b,
c
}
letters l;
l = letters.a;
Console.writeline(l);
a) -1
b) 0
c) a
d) letters.a
Answer: c
-
An enum is a special "class" that represents a group of --------------
Ans: constants
-
Why And When To Use Enums?
Ans: Use enums when you have values that you know aren't going to change, like month days, days, colors, deck of cards, etc.
9.The C# ---------- keyword is used to declare an enumeration.
and: enum
-
The modifiers of an enum declaration have the same meaning as of a class declaration
Ans: class
-
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: Option C
-
What is the value of first enum member by default in C# ?
Ans: Zero
-
What is the type of an enum by default in C# ?
Ans: int
-
Can i use Implicit and Explicit conversion in Enumerator ?
Ans: Yes.