Users Online

· Guests Online: 34

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Questions & Answers ? Enumerations

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

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

Answer: b
Explanation: None.

 

 

 

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

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

 

 

 

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

Answer: d
Explanation: None.

 

 

 

 

 

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

 

 

 

 

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

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

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

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

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

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

Answer: b
Explanation: None.

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.96 seconds
10,845,713 unique visits