Home »
Aptitude Questions and Answers »
C# Aptitude Questions and Answers
C# Enumeration Aptitude Questions and Answers | Set 5
C# Enumeration Aptitude Questions | Set 5: This section contains aptitude questions and answers on C# Enumeration.
Submitted by Nidhi, on April 02, 2020
1) What is the correct output of given code snippets in C#.NET?
using System;
class program
{
enum emp_salary : int
{
emp1,
emp2,
emp4
}
static void Main(string[] args)
{
int sal = (int)emp_salary.emp2;
Console.WriteLine(sal);
}
}
- 0
- 1
- Syntax error
- Runtime exception
Correct answer: 2
1
The above code will print "1" on console screen.
2) What is the correct output of given code snippets in C#.NET?
using System;
class program
{
enum emp_salary : int
{
emp1,
emp2,
emp3
}
static void Main(string[] args)
{
emp_salary.emp1 = 10;
Console.WriteLine(emp_salary.emp2);
}
}
- 10
- 11
- Syntax error
- Runtime exception
Correct answer: 3
Syntax error
The above code will generate syntax error because the left-hand side must be a variable.
3) What is the correct output of given code snippets in C#.NET?
using System;
class program
{
enum emp_salary : int
{
emp1,
emp2,
emp3
}
static void Main(string[] args)
{
emp_salary emp = emp_salary.emp3;
Console.WriteLine(emp.GetType());
}
}
- 2
- emp3
- Syntax error
- program+emp_salary
Correct answer: 4
program+emp_salary
The above will class name with enum name.
4) Can we create an enum with a protected access modifier in C#.NET?
protected Color { Red=1, Green=2};
- Yes
- No
Correct answer: 1
Yes
Yes, we can create an enum with a protected modifier.
5) Can we create an enum with a private access modifier in C#.NET?
private Color { Red=1, Green=2};
- Yes
- No
Correct answer: 1
Yes
Yes, we can create an enum with a private modifier.