列舉的使用

2021-09-30 12:39:39 字數 581 閱讀 1669

寫**有一年了,深深的感覺到列舉非常靈活。標記可數的狀態是往往都少不了它。它是字串和整形數值對應的完美橋梁。下面通過**來展現這一良好的特性吧。

建立相應的列舉:

public enum estate

下面測試**:

estate currentstate = (estate)101;

console.writeline ("int to enum");

console.writeline ("current state is :string value: ,int value:",currentstate,(int)currentstate);

currentstate = (estate)enum.parse (typeof(estate), "stand");

console.writeline ("string to enum");

console.writeline ("current state is :string value: ,int value:",currentstate,(int)currentstate);

執行結果我已經以的形式上傳了。小夥伴感受一下列舉的魅力吧。

列舉的使用

什麼是 列舉?需要在一定的範圍內取值,這個值只能是這個範圍中的任意乙個。舉例 交通訊號燈,有三種顏色,但是每次只能亮三種顏色裡面的任意乙個。列舉關鍵字 enum enum color3列舉的構造方法也是私有的 列舉的使用方法示例 package test04 public class testenu...

列舉的使用

列舉的使用 include define pink 0 define red 1 define green 2 define white 3 define black 5 define yellow 6 enum是關鍵字 裡面的成員是乙個識別符號,列舉常量 列舉型別 成員 列舉成員,列舉常量 enu...

列舉的使用

實體 private canci name enumerated enumtype.string column name name nullable false,length 10 public canci getname public void setname canci name public ...