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

c#枚举数字转枚举

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

Answer & Explanation

Correct answer: 3
Syntax error

The code generates syntax error, we cannot use enum like this.

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

  2. 一月

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:3
语法错误

代码产生语法错误,我们不能像这样使用枚举。

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

Answer & Explanation

Correct answer: 2
FEB

The above code will print "FEB" on the console screen.

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

  2. 二月

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:2
二月

上面的代码将在控制台屏幕上打印“ FEB”

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

Answer & Explanation

Correct answer: 3
Syntax error

The above code will generate syntax error of type conversion.

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

  2. 二月

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:3
语法错误

上面的代码将生成类型转换的语法错误。

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

Answer & Explanation

Correct answer: 1
1

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

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

  2. 二月

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:1
1个

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

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

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes, we can declare an enum outside the class.

5)我们可以在课堂外声明一个枚举吗?
  1. 没有

答案与解释

正确答案:1

是的 ,我们可以在类外声明一个枚举。

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

c#枚举数字转枚举

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值