涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

映射

可以认为是哈希,格式 mapping(_KeyType => _ValueType)

pragma solidity ^0.4.0;

contract MappingExample {
    mapping(address => uint) public balances;

    function update(uint newBalance) public {
        balances[msg.sender] = newBalance;
    }
}

contract MappingUser {
    function f() public returns (uint) {
        MappingExample m = new MappingExample(); // 存储在memory
        m.update(100);
        return m.balances(this);
    }
}
posted on 2018-02-28 11:48  北京涛子  阅读(107)  评论(0编辑  收藏  举报