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); //
}
function isLeft(ActionChoices choice) constant public returns(bool){
if (choice == ActionChoices.Left){
return true; //
}
return false; //1,2,3
}
}
//构造函数
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 lin
1: uint256: sex 1
2: uint256: age 17
*/ Student [] public students; function assgin() public{
students.push(std1);
students.push(std2);
std1.name ='eilinge';
/*
0: string: name eilinge
1: uint256: sex 0
2: uint256: age 15
*/
}
} //映射/字典
contract mappingTest{
mapping(uint => string) id_names; /*
mapping (_key => _values)
键的类型允许除映射外的所有类型,如数组、合约、枚举、结构体.值的类型无限制.
映射可以被视作一个哈希表,其中所有可能的键已被虚拟化的创建,被映射到一个默认值(二进制表示的零)
在映射表中,我们并不存储建的数据,仅仅储存它的keccak256哈希值,用来查找值时使用。
映射类型,仅能用来定义状态变量,或者是在内部函数中作为storage类型的引用
*/
constructor() public{
id_names[0x001] = 'jim';//构造函数内声明的全局变量,任意函数都可以进行调用
id_names[0x002] = 'eilin';
} function getNamebyId(uint id) constant public returns(string){
string name = id_names[id]; //局部变量 name,仅能在本函数内使用,其他函数无法进行调用
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;
}
}

ethereum(以太坊)(七)--枚举/映射/构造函数/修改器的更多相关文章

  1. AutoMapper在MVC中的运用03-字典集合、枚举映射,自定义解析器

    本篇AutoMapper使用场景: ※ 源字典集合转换成目标字典集合 ※ 枚举映射 ※ 自定义解析器 ※ 源中的复杂属性和Get...方法转换成目标属性 源字典集合转换成目标字典集合 □ Domain ...

  2. ethereum(以太坊)(一)

    从这周开始,开始学习以太坊开发--solidity,开始决定往区块链方向发展,毕竟区块链技术应用广泛.一开始接触solidity开发语言不太习惯,毕竟一直在学习python语法,有很多都不能接受.有难 ...

  3. ethereum(以太坊)(十二)--应用(一)__集资(构造函数/映射)

    pragma solidity ^0.4.4; contract funder{ //0xca35b7d915458ef540ade6068dfe2f44e8fa733c //0x14723a09ac ...

  4. ethereum(以太坊)(实例)--"安全的远程购买"

    pragma solidity ^0.4.10; contract Safebuy{ uint public price; address public seller; address public ...

  5. ethereum(以太坊)(四)--值传递与引用传递

    contract Person { string public _name; function Person() { _name = "liyuechun"; } function ...

  6. ethereum(以太坊)(十一)--字节数组(二)

    pragma solidity ^0.4.0; contract test { uint [5] T =[1,2,3,4,5] ;//固定长度的数组:可修改数组内值大小,不支持push,不可更改长度 ...

  7. ethereum(以太坊)(十)--函数修饰符

    pragma solidity ^0.4.0; contract modifierTest{ uint public v1; uint constant v2 =10; //uint constant ...

  8. ethereum(以太坊)(实例)--"简单的公开竞拍"

    说真的,刚开始接触这个竞拍案例--“简单的公开竞拍”,我就抱着简单的心态去查看这个实例,但是自我感觉并不简单.应该是我实力不到家的原因吧!!!233333...不过经过大半天的努力,自己理解完之后,觉 ...

  9. ethereum(以太坊)(十四)--Delete

    pragma solidity ^0.4.10; contract Delete{ /* delete可用于任何变量(除mapping),将其设置成默认值 bytes/string:删除所有元素,其长 ...

随机推荐

  1. 【linux下载方式的区别】wget 、apt-get、yum rpm区别

    1.wget 类似于迅雷,是一种下载工具, 通过HTTP.HTTPS.FTP三个最常见的TCP/IP协议下载,并可以使用HTTP代理名字是World Wide Web”与“get”的结合. 2.yum ...

  2. 使用InstallShield打包VS程序

    使用InstallShield打包VS程序 InstallShield是微软自己的一个打包工具,这个打包工具,有其优势也有其弊端.其优势,可以很好且方便地将.NET平台的控件以及程序所需要的dll打包 ...

  3. c# 截取picturebox部分图像

    Bitmap bit = new Bitmap(renderImage.Width, renderImage.Height); using (Graphics g = Graphics.FromIma ...

  4. 学习.NET好书推荐

    我之前看过很多书,最近也买了些新书,无论已经看过的,还是正准备要看的,我都做了收藏.这些书涉及面较为广泛,都是平时看社区文章和技术杂志时收藏的,全部来自技术达人和架构师们的推荐,经过我的综合评估(销量 ...

  5. Github站点搭建 gh-pages

    首先:把完整代码放在 gh-pages 分支上,设置 gh-pages 为默认分支(习惯性设置,也可以不设置). 网址: http://你的github域名.github.io/项目入口文件夹/ 本宝 ...

  6. ListView优化的时候ViewHolder的简洁写法

    在ListVIew做复用优化的时候,经常会写ViewHolder,还需要很麻烦的去findview,我最讨厌写一堆的这样代码了,今天看到了一个极简的写法,很好用,很简洁啊!!! public stat ...

  7. python模块详解 shelve

    shelve模块是一个简单的k,v 将内存数据通过文件持久化的模块,可以持久化任何pickle可以支持的python数据.简单的说对 pickle的更上一层的封装. 写文件 import shelve ...

  8. Servlet是线程安全的吗?

    Servlet不是线程安全的. 要解释为什么Servlet为什么不是线程安全的,需要了解Servlet容器(即Tomcat)使如何响应HTTP请求的. 当Tomcat接收到Client的HTTP请求时 ...

  9. python数组列表、字典、拷贝、字符串

    python中字符串方法 name = "I teased at life as if it were a foolish game" print(name.capitalize( ...

  10. SAP CRM WebClient UI和Fiori UI混搭并存

    SAP CRM里有个功能可以创建HANA live report,消费HANA Studio里创建的模型. 最后创建好的report长这个样子: 具体创建步骤可以参考我的博客Step by Step ...