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;
}
}

最新文章

  1. git本地提交到远程仓库命令
  2. poj 3468
  3. hdu 2042 - 不容易系列之二
  4. python爬虫代码
  5. v.size() return size_t not int 返回无符号整型数
  6. 【二进制】FZU 2062 Suneast & Yayamao
  7. Selenium webdriver 常见问题
  8. ArrayList 源码分析
  9. GIT入门笔记(7)- 修改文件并向版本库提交
  10. maven管理的jsp应用如何添加servlet、jsp相关依赖(org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp)
  11. 设计一个卖不同种类车的4s店
  12. vue 及sass安装
  13. PHP中的反射模拟框架中控制器的调度
  14. android 图片内存管理
  15. react-router V4中的url参数
  16. HTML 引入Css样式
  17. (转)C++初始化与赋值
  18. Spring boot 配置文件 使用占位符号
  19. Navigation and Pathfinding
  20. WSDL语法

热门文章

  1. 介绍几个关于C/C++程序调试的函数
  2. powerdesigner低版本打开高版本方式为只读导致无法保存PD只读read-only-mode
  3. C#开发usb通知之bulk传输
  4. mysql-sql命令
  5. spring-boot学习之属性配置
  6. AngularJS 指令解析(一)
  7. u-boot分析(十一)----MMU简单分析|u-boot分析大结局|学习规划
  8. Struts2_带参数的结果集
  9. Java—数组和方法
  10. centos7 安装sqlserver驱动以及扩展