c#枚举数字转枚举_C#枚举能力问题和解答 套装5

c#枚举数字转枚举

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

Answer & Explanation

Correct answer: 2
1

The above code will print "1" on console screen.

1)C#.NET中给定代码段的正确输出是什么?
  1. 0

  2. 1个

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:2
1个

上面的代码将在控制台屏幕上显示“ 1”

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

Answer & Explanation

Correct answer: 3
Syntax error

The above code will generate syntax error because the left-hand side must be a variable.

2)C#.NET中给定代码段的正确输出是什么?
  1. 10

  2. 11

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:3
语法错误

上面的代码将产生语法错误,因为左侧必须是变量。

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

Answer & Explanation

Correct answer: 4
program+emp_salary

The above will class name with enum name.

3)C#.NET中给定代码段的正确输出是什么?
  1. 2

  2. emp3

  3. 语法错误

  4. 程序+ emp_salary

答案与解释

正确答案:4
程序+ 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

Answer & Explanation

Correct answer: 1
Yes

Yes, we can create an enum with a protected modifier.

4)我们可以在C#.NET中使用受保护的访问修饰符创建一个枚举吗?
  1. 没有

答案与解释

正确答案:1

是的 ,我们可以创建一个带有保护修饰符的枚举。

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

  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes, we can create an enum with a private modifier.

5)我们可以在C#.NET中使用私有访问修饰符创建一个枚举吗?
  1. 没有

答案与解释

正确答案:1

是的 ,我们可以使用私有修饰符创建一个枚举。

翻译自: https://www.includehelp.com/dot-net/csharp-enumeration-aptitude-questions-and-answers-5.aspx

c#枚举数字转枚举

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值