日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ethereum(以太坊)(七)--枚举/映射/构造函数/修改器

發(fā)布時間:2023/12/20 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ethereum(以太坊)(七)--枚举/映射/构造函数/修改器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
pragma solidity ^0.4.10;//枚舉類型 contract enumTest{enum ActionChoices{Left,Right,Straight,Still}// 0 1 2 3//input/output uint ActionChoices public _choice;ActionChoices defaultChoice = ActionChoices.Straight;function setStraight(ActionChoices choice) public{_choice = choice;}function getDefaultChoice() constant public returns(uint){return uint(defaultChoice); //2 }function isLeft(ActionChoices choice) constant public returns(bool){if (choice == ActionChoices.Left){return true; //0 }return false; //1,2,3 } } //構(gòu)造函數(shù) contract StructTest{struct Student{string name;uint sex;uint age;//uint year =15;ParserError: Expected ';' but got '=':Cannot be assigned within the constructor,unless use constructor public{} }Student public std1 = Student('lily',0,15);Student public std2 = Student({name:'lin',sex:1,age:17});/*0: string: name lin1: uint256: sex 12: uint256: age 17*/Student [] public students;function assgin() public{students.push(std1);students.push(std2);std1.name ='eilinge';/*0: string: name eilinge1: uint256: sex 02: uint256: age 15*/} }//映射/字典 contract mappingTest{mapping(uint => string) id_names;/*mapping (_key => _values)鍵的類型允許除映射外的所有類型,如數(shù)組、合約、枚舉、結(jié)構(gòu)體.值的類型無限制.映射可以被視作一個哈希表,其中所有可能的鍵已被虛擬化的創(chuàng)建,被映射到一個默認值(二進制表示的零)在映射表中,我們并不存儲建的數(shù)據(jù),僅僅儲存它的keccak256哈希值,用來查找值時使用。映射類型,僅能用來定義狀態(tài)變量,或者是在內(nèi)部函數(shù)中作為storage類型的引用*/constructor() public{id_names[0x001] = 'jim';//構(gòu)造函數(shù)內(nèi)聲明的全局變量,任意函數(shù)都可以進行調(diào)用id_names[0x002] = 'eilin';}function getNamebyId(uint id) constant public returns(string){string name = id_names[id]; //局部變量 name,僅能在本函數(shù)內(nèi)使用,其他函數(shù)無法進行調(diào)用return name;} }//修改器 pragma solidity ^0.4.10;contract modifierTest{address owner=msg.sender;uint public v3;modifier onlyowner(address own) {require(own == owner);_;}function setv3() onlyowner(msg.sender) {v3 = 10;} }

?

轉(zhuǎn)載于:https://www.cnblogs.com/eilinge/p/9959372.html

總結(jié)

以上是生活随笔為你收集整理的ethereum(以太坊)(七)--枚举/映射/构造函数/修改器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。