更新一些学习内容
parent
4dd8b0fefa
commit
f55ed8536e
@ -0,0 +1,30 @@
|
|||||||
|
// SPDX-License-Identifier: UNLICENSED
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
contract ArrayTest {
|
||||||
|
|
||||||
|
// 以下标为定义的访问器 1 => 2
|
||||||
|
uint [] public u = [1, 2, 3];
|
||||||
|
|
||||||
|
string s = "abcdefg";
|
||||||
|
|
||||||
|
// 获取数组的长度 => string 可以转换成 bytes
|
||||||
|
function h() public constant returns (uint) {
|
||||||
|
return bytes(s).length; // 7
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回下标为1的元素
|
||||||
|
function f() public view returns (byte) {
|
||||||
|
|
||||||
|
// 调用下面的数组
|
||||||
|
g([uint(1), 2, 3]);
|
||||||
|
|
||||||
|
return bytes(s)[1]; // b -> asc 码 0x62
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数组作为参数进行传递
|
||||||
|
function g(uint[3] _data) public constant {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
// SPDX-License-Identifier: UNLICENSED
|
||||||
|
pragma solidity ^0.4.16;
|
||||||
|
|
||||||
|
contract TestAddr {
|
||||||
|
|
||||||
|
function deposit() public payable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 获取余额 */
|
||||||
|
function getBalance() public constant returns (uint) {
|
||||||
|
return this.balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 转移以太 */
|
||||||
|
function transferEther(address towho) public {
|
||||||
|
towho.transfer(10); // send 方法可能会失败
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue