Home »
Aptitude Questions and Answers »
C# Aptitude Questions and Answers
C# Enumeration Aptitude Questions and Answers | Set 3
C# Enumeration Aptitude Questions | Set 3: 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
{
static void Main(string[] args)
{
enum months {JAN=0,FEB,MAR}
Console.WriteLine(months.JAN);
}
}
- 0
- JAN
- Syntax error
- Runtime exception
Correct answer: 3
Syntax error
The code generates syntax error, we cannot use enum like this.
2) What is the correct output of given code snippets in C#.NET?
using System;
class program
{
enum months { JAN = 0, FEB, MAR }
static void Main(string[] args)
{
Console.WriteLine(months.FEB);
}
}
- 1
- FEB
- Syntax error
- Runtime exception
Correct answer: 2
FEB
The above code will print "FEB" on the console screen.
3) What is the correct output of given code snippets in C#.NET?
using System;
class program
{
enum months { JAN = 0, FEB, MAR }
static void Main(string[] args)
{
int val = months.FEB;
Console.WriteLine(val);
}
}
- 1
- FEB
- Syntax error
- Runtime exception
Correct answer: 3
Syntax error
The above code will generate syntax error of type conversion.
4) What is the correct output of given code snippets in C#.NET?
using System;
class program
{
enum months { JAN = 0, FEB, MAR }
static void Main(string[] args)
{
int val = (int)months.FEB;
Console.WriteLine(val);
}
}
- 1
- FEB
- Syntax error
- Runtime exception
Correct answer: 1
1
The above code will print "1" on the console screen.
5) Can we declare an enum outside the class?
- Yes
- No
Correct answer: 1
Yes
Yes, we can declare an enum outside the class.