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. POJ 1236——Network of Schools——————【加边形成强连通图】

    Network of Schools Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u ...

  2. [Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]

    Background: Servlet version 3.1(3.0之后就有了@WebServlet注解) Error 严重: Failed to destroy end point associa ...

  3. [LeetCode]14. Longest Common Prefix最长公共前缀

    Write a function to find the longest common prefix string amongst an array of strings. If there is n ...

  4. WinRAR(WinZip)压缩与解压实现(C#版Window平台)

    本文的原理是借助Windows平台安装的WinRAR(WinZip)实现C#程序的调用(注:WinRAR压缩解压WinZip同样适用). 先来看WinRAR(WinZip)自身的支持调用命令: 压缩命 ...

  5. Controller的使用

  6. web项目无法被Eclipse的Tomcat识别的解决办法

    Eclipse 导入外部项目无法识别为web项目并且无法在部署到tomcat下 1.进入项目目录,找到 .project 文件: 2.找到 <natures> 代码段,在里面加入如下标签内 ...

  7. 栅格那点儿事(四B)---多波段栅格数据的显示

    多波段栅格数据的显示 我上面说了这么多,可能有的人会觉得平时也根本用不上.自然,说起影像数据,大家接触到对多的就是最最常见的航片或卫片.对于这种栅格数据呢,大多数的场景下,都只需实现一个效果,就是最接 ...

  8. Cg shadow of sphere

    参考自:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Soft_Shadows_of_Spheres using UnityEngine; ...

  9. webpack前端构建工具学习总结(一)之webpack安装、创建项目

    npm是随nodeJs安装包一起安装的包管理工具,能解决NodeJS代码部署上的很多问题: 常见的使用场景有以下几种: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从NPM服务器 ...

  10. 解决ubuntu的chkconfig[/sbin/insserv 无法找到路径问题]

    http://www.cnblogs.com/lost-1987/archive/2012/10/17/2727285.html 今天在虚拟机里做DRBD实验,使用chkconfig管理服务的时候,出 ...