Solidify實現一個智慧合約10(列舉)
阿新 • • 發佈:2018-12-15
程式碼示例
pragma solidity ^0.4.4; contract Mj { enum ActionChoices {GoLeft,GoRight,GoStraight,SitStill} ActionChoices _choice; ActionChoices constant defaultChoice = ActionChoices.GoStraight; //constant定義常量,不能修改。 function setGoStraight(ActionChoices choice) { _choice = choice; } function getChoice() constant returns (ActionChoices) { return _choice; } function getDefault() pure public returns (uint) { return uint(defaultChoice); } }
enum是關鍵詞,ActionChoices是自己定義的型別,該型別包含4個引數,當個數在255以為,該型別的資料型別時uint8,超過時為uint16。