Mapping 创建语法: mapping(keyType => valueType)
。
keyType
可以是任何内置值类型、字节、字符串或任何约定。
valueType
可以是任何类型,包括另一个映射或数组。
Mappings 不可迭代。
合约示例:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract Mapping {
// Mapping from address to uint
mapping(address => uint) public myMap;
function get(address _addr) public view returns (uint) {
// Mapping always returns a value.
// If the value was never set, it will return the default value.
return myMap[_addr];
}
function set(address _addr, uint _i) public {
// Updat