列舉型別的區分

2021-07-16 13:52:19 字數 1479 閱讀 6579

原文出處:

一般情況下,我們採用c風格的enum關鍵字可以定義列舉型別。

[cpp]view plain

copy

enum uiviewanimationtransition;  

[cpp]view plain

copy

//位移操作列舉定義

enum ;  

typedef nsuinteger uiviewautoresizing;//使用nsuinteger的地方可以使用uiviewautoresizing,//uiviewautoresizing相當於nsuinteger的乙個別名使用。

//因此乙個uiviewautoresizing的變數可以直接賦值給nsuinteger

[cpp]view plain

copy

typedef ns_enum(nsinteger, uiviewanimationtransition) ;  

typedef ns_options(nsuinteger, uiviewautoresizing) ;  

這兩個巨集的定義在foundation.framework的nsobjcruntime.h中:

[cpp]view plain

copy

#if (__cplusplus && __cplusplus >= 201103l && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))

#define ns_enum(_type, _name) enum _name : _type _name; enum _name : _type

#if (__cplusplus)

#define ns_options(_type, _name) _type _name; enum : _type

#else

#define ns_options(_type, _name) enum _name : _type _name; enum _name : _type

#endif

#else

#define ns_enum(_type, _name) _type _name; enum

#define ns_options(_type, _name) _type _name; enum

#endif 將

[cpp]view plain

copy

typedef ns_enum(nsinteger, uiviewanimationtransition)  uiviewanimationtransition;  

等效於上述定義。

1. 2.

Delphi型別區分 列舉

delphi列舉 列舉 代表值的名字列表。用內建型別 如 integer 也可以儲存狀態,列舉比內建資料更安全 更見名知義。列舉是有序型別。基於在型別定義中的出現次序,列舉元素自動地分配連續值。從第乙個位置的0 開始到最後乙個位置的n 1 結束。列舉型別的定義 type 列舉型別識別符號 識別符號1...

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

列舉型別中不僅可以宣告列舉的名稱,還可以加入附加的值如下式 public static enum pushtype public string tostring 其中push type sys稱為列舉的name,0則為列舉型別的value,那如何才能根據列舉型別的value獲取列舉型別的例項呢?見下...

根據列舉的型別名稱獲取列舉型別列表

前端進行搜尋或其他操作時需要獲取列舉列表,每個列舉寫乙個介面比較繁瑣,所以這裡根據列舉型別名獲取列表 以下為 示例 public class enumdto 值 public int value 描述 public string description using system.componentm...