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

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

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());
    }
}
  1. 2
  2. emp3
  3. Syntax error
  4. program+emp_salary

4) Can we create an enum with a protected access modifier in C#.NET?
protected Color { Red=1, Green=2};
  1. Yes
  2. No

5) Can we create an enum with a private access modifier in C#.NET?
private Color { Red=1, Green=2};
  1. Yes
  2. No





Comments and Discussions!

Load comments ↻





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