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);
    }
}
  1. 0
  2. JAN
  3. Syntax error
  4. Runtime exception

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. 1
  2. FEB
  3. Syntax error
  4. Runtime exception

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. 1
  2. FEB
  3. Syntax error
  4. Runtime exception

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. 1
  2. FEB
  3. Syntax error
  4. Runtime exception

5) Can we declare an enum outside the class?
  1. Yes
  2. No





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.