Reference Types
Các kiểu dữ liệu tham chiếu
Struct
Struct giúp định nghĩa một kiểu dữ liệu bao gồm nhiều trường dữ liệu
pragma solidity >=0.4.0 <0.6.0;
contract Ballot {
struct Voter { // Struct
uint weight;
bool voted;
address delegate;
uint vote;
}
}Arrays
Array có thể có độ dài cố định hoặc độ dài tuỳ biến.
Một array với kiểu dữ liệu là T và độ dài là k thì cú pháp là T[k], với độ dài linh hoạt thì là T[]
pragma solidity >=0.4.16 <0.6.0;
contract C {
function f(uint len) public pure {
uint[] memory a = new uint[](7);
bytes memory b = new bytes(len);
assert(a.length == 7);
assert(b.length == len);
a[6] = 8;
}
}
Last updated
Was this helpful?