C# Questions & Answers on Enumerations for Freshers

1. Choose the correct statements about enum used in C#.NET?

a) An enum variable cannot have a private access modifier
b) An enum variable can be defined inside a class or a namespace
c) An enum variable cannot have a protected access modifier
d) An enum variable cannot have a public access modifier
Answer: c
2. Which among the following cannot be used as a datatype for an enum in C#.NET?

a) short
b) double
c) int
d) all of the mentioned
Answer: b
3. Choose the correct output for the C#.NET code given below?
  1. enum days:int
  2. {
  3.     sunday = -3,
  4.     monday,
  5.     tuesday
  6. }
  7. Console.WriteLine((int)days.sunday);
  8. Console.WriteLine((int)days.monday);
  9. Console.WriteLine((int)days.tuesday);
a) -3 0 1
b) 0 1 2
c) -3 -2 -1
d) sunday monday tuesday
Answer: c
4. Choose the correct statement about the C#.NET code given below?
  1. enum color:byte
  2. {
  3.     yellow = 500,
  4.     green = 1000,
  5.     pink = 1300
  6. }
a) byte value cannot be assigned to enum elements
b) enum elements should always take successive values
c) enum must always be of int type
d) When the valid range of byte exceeds, the compiler will report an error
Answer: d
5. 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
6. Choose the correct output for given set of code?
  1.   enum per
  2.  {
  3.      a, 
  4.      b, 
  5.      c, 
  6.      d, 
  7.  }
  8.  per.a = 10;
  9.  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.
7. Choose the correct output for given set of code?
  1. enum color:int
  2. {
  3.     red,
  4.     green,
  5.     blue = 5,
  6.     cyan,
  7.     pink = 10,
  8.     brown
  9. }
  10. console.writeline((int)color.green);
  11. console.writeline((int)color.brown);
a) 2 10
b) 2 11
c) 1 11
d) 1 5
Answer: c
Output: 1 11
8. Correct the output for the C#.NET code given below?
  1. enum letters
  2. {
  3.     a,
  4.     b,
  5.     c
  6. } 
  7. letters l;
  8. l = letters.a;
  9. Console.writeline(l);
a) -1
b) 0
c) a
d) letters.a
Answer: c
Output: a
9. Correct output for the C#.NET code given below is?
  1.  enum colors
  2.  {
  3.      red,
  4.      black,
  5.      pink
  6.  }
  7.  colors s = colors.black;
  8.  type t;
  9.  t = c.GetType();
  10.  string[] str;
  11.  str = Enum.GetNames(t);
  12.  Console.WriteLine(str[0]);
a) 0
b) black
c) red
d) 1
Answer: c
Output: red
10. Choose the correct statement about enum used in C#.NET ?

a) By default the first enumerator has a value equal to the number of elements present in the list
b) Values of the enum elements cannot be populated from database
c) The value of each successive enumerator is decreased by 1
d) An enumerator has a white space in its name
Answer: b
11. Which among the following differentiates enum in C#.NET from enum in C language?

a) C is stricly a typed language, C#.NET also is a strictly typed language
b) In C, language variables of enum types can be used interchangeably with integers using type casts while enum variables cannot be used as a normal integers in C#.NET
c) None of the mentioned
d) All of the mentioned
Answer: b

Related

Multiple Choice Questions 4415263855255768977

Post a Comment

emo-but-icon

item