使用列舉型別的值建立列舉型別

2021-07-03 07:28:04 字數 386 閱讀 5990

列舉型別中不僅可以宣告列舉的名稱,還可以加入附加的值如下式:

public static enum pushtype

public string tostring()

}

其中push_type_sys稱為列舉的name,0則為列舉型別的value,那如何才能根據列舉型別的value獲取列舉型別的例項呢?

**見下:

public static pushtype getpushtype(string value) 

}return push_type_user;

}

通過乙個內部的遍歷和value值的判斷,即可返回列舉型別的例項。

visual C ( )使用列舉和結構建立值型別

9.2 使用結構 用關鍵字enum。enum season season colorful season.fall console.writeline colorful 列舉內部的每個元素都關聯乙個整數值。預設第乙個元素對應0,後面每個元素對應的整數都遞增1。也可以手動將特定整數常量和列舉型別的字面...

使用列舉型別

using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui usin...

列舉型別的使用

1.列舉的定義列舉型別定義的一般形式為 enum 列舉名 在列舉值表中應羅列出所有可用值。這些值也稱為列舉元素。例如 該列舉名為weekday,列舉值共有7個,即一周中的七天。凡被說明為weekday型別變數的取值只能是七天中的某一天。2.列舉變數的說明 如同結構和聯合一樣,列舉變數也可用不同的方式...