C# Questions & Answers – Enumerations

This section of our 1000+ C# MCQs focuses on enumerations of C# Programming Language.

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
View Answer

Answer: c
Explanation: None.

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
View Answer

Answer: b
Explanation: None.

3. What will be the output of the following C# code?

advertisement
advertisement
  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
View Answer

Answer: c
Explanation: None.
Note: Join free Sanfoundry classes at Telegram or Youtube

4. What will be the correct statement of the following C# code?

  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
View Answer

Answer: d
Explanation: None.
advertisement

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
View Answer

Answer: d
Explanation: None.
advertisement

6. What will be the output of the following C# 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
View Answer

Answer: d
Explanation: It will report an error since enum element cannot be assigned a value outside the enum declaration.

7. What will be the output of the following C# 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
View Answer

Answer: c
Explanation: None.
Output:

 1 11

8. What will be the output of the following C# code?

  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
View Answer

Answer: c
Explanation: None.
Output:

a

9. What will be the output of the following C# code?

  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
View Answer

Answer: c
Explanation: None.
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
View Answer

Answer: b
Explanation: None.

11. Which among the following differentiates enum in C#.NET from enum in C language?
a) C is strictly 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
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all areas of C# language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.