ethereum(以太坊)(十四)--Delete
阿新 • • 發佈:2018-12-07
delet byte 長度 stat check eth delete ppi ++
pragma solidity ^0.4.10; contract Delete{ /* delete可用於任何變量(除mapping),將其設置成默認值 bytes/string:刪除所有元素,其長度變為0 bytes32:重置所有索引的值 mapping:什麽都不會發生 mapping(key=>value)中的key:刪除與該鍵相關的值 */ string public str1 =‘nihao‘; function deletstr() public{delete str1; } function setstr() public returns(string){ return str1=‘NIHAO‘; } uint[5] public b1=[uint(10),2,3,4,5]; uint[] public b2=new uint[](10); function initAccary() public{ for(uint i;i<10;i++){ b2[i] = i; } }function deleStaticAccary() public{ delete b1; } function deleDhcpAccary() public{ delete b2; } function getlength() public view returns(uint,uint){ return (b1.length,b2.length); } mapping(uint=>bool) public m1; function f1() public{ m1[1]=true; m1[2]=false; } function deleM(uint a) public{ delete m1[a]; } struct Person{ string name; mapping(string =>uint) NameSore; } //Person p2=Person(‘duke‘,([‘duke‘][90])); Person public p1; function InitP1() public{ p1.name=‘duke‘; p1.NameSore[‘duke‘]=90; } function checkP1() public view returns(string,uint){ return(p1.name,p1.NameSore[‘duke‘]); } function delP1() public{ delete p1; } }
ethereum(以太坊)(十四)--Delete