c#枚舉數字轉枚舉_C#枚舉能力問題和解答 套裝4

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#枚舉數字轉枚舉

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379964.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379964.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379964.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Java——匿名內部類實現線程的兩種方式

package com.yy.thread;public class Demo4_Thread {public static void main(String[] args) {demo1(); //匿名內部類,第一種,繼承Threaddemo2(); //匿名內部類,第二種,實現Runnable接口 }private static void…

zlib1.2.5的編譯

zlib1.2.5沒有了1.2.4的vc6工程,只好使用命令行編譯。通過win32/Makefile.msc發現有4種編譯方式,如下:# Usage:# nmake -f win32/Makefile.msc (standard build)# nmake -f win32/Makefile.msc LOC-DFOO …

python網絡編程--UDP客戶端

0x01 環境 python、pycharm 0x02 程序 # -*- coding:utf-8 -*-import sockettarget_host127.0.0.1 target_part80#創建一個socket對象 client socket.socket(socket.AF_INET,socket.SOCK_DGRAM)#發送一些數據 client.sendto(AAAAAA,(target_host,target_part))#接收到的消息 …

window.open參數和技巧

【1、最基本的彈出窗口代碼】 <SCRIPT LANGUAGE"javascript"> <!-- window.open (page.html) --> </SCRIPT> 因為著是一段javascripts代碼&#xff0c;所以它們應該放在<SCRIPT LANGUAGE"javascript">標簽和</script>之間。…

java jar包示例_Java包getImplementationTitle()方法和示例

java jar包示例包類的getImplementationTitle()方法 (Package Class getImplementationTitle() method) getImplementationTitle() method is available in java.lang package. getImplementationTitle()方法在java.lang包中可用。 getImplementationTitle() method is used to…

Java——獲取和設置多線程的名稱

給名字進行賦值有兩種方式&#xff1a; 1&#xff0c;通過構造去賦值 Thread(String name) 直接在構造方法里面傳一個名字就行了2&#xff0c;通過set設置的方法進行賦值 package com.yy.threadmethod;public class Demo1_Name {public static void main(String[] args) {dem…

十三、oracle 數據字典和動態性能視圖

一、概念數據字典是oracle數據庫中最重要的組成部分&#xff0c;它提供了數據庫的一些系統信息。動態性能視圖記載了例程啟動后的相關信息。 二、數據字典1)、數據字典記錄了數據庫的系統信息&#xff0c;它是只讀表和視圖的集合&#xff0c;數據字典的所有者為sys用戶。2)、用…

python網絡編程---TCP服務器

0x01 環境 python2 pycharm 0x02 程序 客戶端程序&#xff1a; # -*- coding:UTF-8 -*- import sockettarget_hostwww.baidu.com target_port80target_hostlocalhost target_port3345 dataABCDEF# 創建一個socket對象 client socket.socket(socket.AF_INET,socket.SOCK_STRE…

C# 獲取磁盤容量

/// 獲取指定驅動器的空間總大小(單位為B) /// </summary> /// <param name"str_HardDiskName">只需輸入代表驅動器的字母即可 </param> /// <returns> </returns> public static long GetHardDi…

Java——獲取當前線程的對象(currentThread())(兩種方式)

package com.yy.threadmethod;public class Demo2_CurrentThread { /*** public static Thread currentThread()返回對當前正在執行的線程對象的引用。 * 返回&#xff1a;當前執行的線程。返回的是一個Thread* 該方法主要是為了協助 實現通過Runnable接口來對線程進行設置…

HDU2501_多米諾骨牌

題目大意&#xff1a; 有一個大小是 2 x n 的網格&#xff0c;現在需要用2種規格的骨牌鋪滿&#xff0c;骨牌規格分別是 2 x 1 和 2 x 2&#xff0c;請計算一共有多少種鋪設的方法。 解題思路&#xff1a; 找出遞推公式&#xff1a; f[i] f[i-1] f[i-2] * 2; 代碼&#xff1a…

java jar包示例_Java包getSpecificationVendor()方法和示例

java jar包示例包類的getSpecificationVendor()方法 (Package Class getSpecificationVendor() method) getSpecificationVendor() method is available in java.lang package. getSpecificationVendor()方法在java.lang包中可用。 getSpecificationVendor() method is used to…

sys.argv和getopt

0x01 sys.argv sys.argv用來讀取命令行參數&#xff0c;保存程序的文件名和命令參數&#xff0c;讀入的參數以列表保存 import sysprint sys.argv print type(sys.argv)可以看到&#xff0c;sys.argv把空格當成分隔符&#xff0c;空格兩邊的值當做sys.argv的一個元素&#xf…

[導入]《大話設計模式》重印公告

摘要: 《大話設計模式》12月中旬上市&#xff0c;至2008年1月底僅僅一個多月&#xff0c;5000冊即銷售一空&#xff0c;清華大學出版社已經開始重印&#xff0c;也就是說很快可以在二月底或三月初看到新印刷修正過大部分錯誤的《大話設計模式》。 閱讀全文[新聞]《人民日報市場…

Java——線程的四種不同形式

一&#xff0c;休眠線程 public static void sleep(long millis) throws InterruptedException 在指定的毫秒數內讓當前正在執行的線程休眠&#xff08;暫停執行&#xff09;&#xff0c;此操作受到系統計時器和調度程序精度和準確性的影響。該線程不丟失任何監視器的所屬權。…

hdu1053 Entropy hdu2527 Safe Or Unsafe

裸裸的哈弗曼編碼&#xff0c;求出哈弗曼編碼的路徑長度&#xff0c;注意整個字符串為一種字符的情況 View Code #include<iostream>#include<queue>#include<algorithm>#include<vector>using namespace std;struct node{int u,w; node(int a0,in…

Java ListResourceBundle getContents()方法與示例

ListResourceBundle類的getContents()方法 (ListResourceBundle Class getContents() method) getContents() method is available in java.util package. getContents()方法在java.util包中可用。 getContents() method is used to get the contents into the form of an Obje…

DOM元素的所有子元素 .elements

.elements屬性用來獲取某個DOM元素的所有子元素&#xff0c;是個很有用的屬性&#xff0c;可用于用className來獲取指定元素等用途。 轉載于:https://www.cnblogs.com/cly84920/archive/2008/08/06/4427136.html

sys.stdin.read和raw_input函數

sys.stdin.read函數 例子&#xff1a; import sysreadsys.stdin.read() for i in range(len(read)):print i,read[i],-1運行&#xff0c;當執行到readsys.stdin.read()會阻塞&#xff0c;等待我們輸入 我們輸入&#xff1a; h e當輸入&#xff0c;ctrlD結束輸入&#xff0c…

Java ObjectOutputStream writeFields()方法與示例

ObjectOutputStream類writeFields()方法 (ObjectOutputStream Class writeFields() method) writeFields() method is available in java.io package. 在java.io包中提供了writeFields()方法 。 writeFields() method is used to write the buffered fields to the ObjectOutpu…