C# Enumeration Aptitude Questions and Answers | Set 4

C# Enumeration Aptitude Questions | Set 4: 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 = 10000,
        emp2 = 15000,
        emp4 = 20000
    }
    static void Main(string[] args)
    {
        int sal = (int)emp_salary.emp2;

        Console.WriteLine(sal);
    }
}
  1. 10000
  2. 15000
  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 : byte
    {
        emp1 = 10000,
        emp2 = 15000,
        emp4 = 20000
    }
    static void Main(string[] args)
    {
        int sal = (int)emp_salary.emp2;

        Console.WriteLine(sal);
    }
}
  1. 10000
  2. 15000
  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 : float
    {
        emp1 = 10000,
        emp2 = 15000,
        emp4 = 20000
    }
    static void Main(string[] args)
    {
        int sal = (int)emp_salary.emp2;

        Console.WriteLine(sal);
    }
}
  1. 10000
  2. 15000
  3. Syntax error
  4. Runtime exception

4) What is the correct output of given code snippets in C#.NET?
using System;

class program
{
    enum emp_salary : int
    {
        emp1 = 10000,
        emp2 = 15000,
        emp4 = 20000
    }
    static void Main(string[] args)
    {
        emp_salary sal = emp_salary.emp2;

        if (sal == emp_salary.emp2)
        {
            Console.WriteLine("15000");
        }
    }
}
  1. 10000
  2. 15000
  3. Syntax error
  4. Runtime exception

5) What is the correct output of given code snippets in C#.NET?
using System;

class program
{
    int A = 10000;
    int B = 15000;
    int C = 20000;

    enum emp_salary : int
    {
        emp1 = A,
        emp2 = B,
        emp4 = C
    }
    
    static void Main(string[] args)
    {
        emp_salary sal = emp_salary.emp2;

        if (sal == emp_salary.emp2)
        {
            Console.WriteLine("15000");
        }
    }
}
  1. 10000
  2. 15000
  3. Syntax error
  4. Runtime exception





Comments and Discussions!

Load comments ↻





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