c#枚举数字转枚举

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

Answer & Explanation

Correct answer: 2
15000

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

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

  1. 10000

  2. 15000

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:2
15000

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

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

Answer & Explanation

Correct answer: 3
Syntax error

The above code will generate syntax error because the value of enums is outside the range of byte.

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

  1. 10000

  2. 15000

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:3
语法错误

上面的代码将产生语法错误,因为enums的值超出了字节范围。

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

Answer & Explanation

Correct answer: 3
Syntax error

The above code will generate syntax error because we cannot use a float with enum like this.

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

  1. 10000

  2. 15000

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:3
语法错误

上面的代码将产生语法错误,因为我们不能像这样使用带枚举的浮点数 。

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

Answer & Explanation

Correct answer: 3
15000

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

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

  1. 10000

  2. 15000

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:3
15000

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

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

Answer & Explanation

Correct answer: 3
Syntax error

The above code will generate a syntax error.

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

  1. 10000

  2. 15000

  3. 语法错误

  4. 运行时异常

答案与解释

正确答案:3
语法错误

上面的代码将生成语法错误。

◀ C# Enumeration Aptitude | Set 3 C# Enumeration Aptitude | Set 5 ▶
#C#枚举能力| 设置3 C#枚举能力| 设置5▶

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

c#枚举数字转枚举

c#枚举数字转枚举_C#枚举能力问题和解答 套装4相关推荐

  1. c枚举类型enum例题_c枚举类型enum用法 枚举类型enum用法 怎么去取所有

    JUDGE(S W ) 指 W 属于 S 枚举类型还是自定义函数里的2个变量不要太久太久不联系我,我怕我一不小心把你忘了. (1) 枚举型是一个集合,集合中的元素(枚举成员)是一些命名的整型常量,元素 ...

  2. c# 命名空间命名规范_C#命名空间能力问题和解答 套装3

    c# 命名空间命名规范 1) There are following namespaces are given below, which is correct about "using&qu ...

  3. c#c#继承窗体_C#继承能力问题和解答 套装5

    c#c#继承窗体 1) Which keyword is used to call a superclass constructor from child class? super top const ...

  4. c# 命名空间命名规范_C#命名空间能力问题和解答 套装2

    c# 命名空间命名规范 1) Can we create a nested namespace in C#.NET? Yes No Answer & Explanation Correct a ...

  5. c-style字符字符串_C字符串-能力问题与解答

    c-style字符字符串 C programming String Aptitude Questions and Answers: In this section you will find C Ap ...

  6. osi模型:七层模型介绍_联网| OSI模型能力问题和解答 套装1

    osi模型:七层模型介绍 1) There are the following statements that are given below, which of them are correct a ...

  7. C# ToString格式字符串整理(Format)(数字、日期和枚举的标准格式设置说明符)

    日常开发中,格式字符串的情况非常多.经常也会忘记,经常去查有些麻烦,所以今天就花点时间做个整理. 格式字符串用的比较多的有数字.日期与枚举的格式化. 一.数字格式字符串 C或c 本地货币格式 D或d ...

  8. c枚举类型enum例题_c语言之枚举类型(enum)

    1 枚举类型 1 . 如果一个变量只有几种可能的值,则可以定义为"枚举类型":所谓"枚举"就是把可能的值一一的列举出来,变量的值只限于列举出来的值的范围, 如: ...

  9. java枚举数字_Java枚举类型的使用,数值的二进制表示

    一.Java枚举类型的使用 首先请看这段代码: packagejava上课;public classEnumTest {public static voidmain(String[] args) { ...

最新文章

  1. ti的硬件时钟和系统时钟同步
  2. 写代码时发现......还是 SpringBoot 牛逼!一篇拿下
  3. RedHat linux inittab详解
  4. 【年终总结】2020年有三AI做了什么,2021年我们要做什么?
  5. Linux下串口编程遇 接收数据错误问题及原因
  6. java 配置文件 路径问题_java 配置文件的路径问题
  7. vue cli3.0创项目报错‘This may cause things to work incorrectly. Make sure to use the same version for b’
  8. zabbix mysql复制延迟_Zabbix监控mysql主从复制状态
  9. Jenkins+Github(Robotframework代码)
  10. java排序算法学习(一)--冒泡排序
  11. 程序设计语言的发展过程
  12. 酷我音乐盒html代码,酷我音乐盒2018
  13. C语言中插入法的应用
  14. 网络转型中的设备硬件形态选择初探
  15. 微信小程序 学习第一天
  16. 外汇交易中的结汇,售汇,收汇,付汇是什么意思
  17. apex英雄哪个服务器稳定,apex英雄哪个服务器好
  18. Spring Boot 使用 HikariCP 连接池配置详解
  19. JAVA中DateTime获取当前时间
  20. C++判断素数(求素数)

热门文章

  1. 记一次应急响应到溯源入侵者
  2. 5天玩转mysql视频教程_六天带你玩转MySQL
  3. 操作系统饥饿现象_操作系统心得体会
  4. 你真的懂js获取可视区宽高吗
  5. safari 音频播放问题
  6. Windows 自启动总结《转》
  7. Android 调用系统的分享[完美实现同一时候分享图片和文字]
  8. 微型计算机用什么评价判断,环评中常用评价等级的判定
  9. bmp调色板颜色信息重复_如何更改 Linux 终端颜色主题 | Linux 中国
  10. java开发 职业技能_java编程开发程序员需要具备哪些职业技能