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);
    }
}
  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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.