solidity mapping of mapping
生活随笔
收集整理的這篇文章主要介紹了
solidity mapping of mapping
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
solidity mapping of mapping,兩層映射,用的時候可以像二維數組一樣去訪問和修改值,非常方便。
以下代碼示例中的這一句:
mapping(string => mapping(uint => uint)) prices
相當于建立了一個price數據庫表(只不過存在內存中),表結構為:index, date, price, key值為index + date。
pragma solidity ^0.4.21;contract mappingOfMapping{mapping(string => mapping(uint => uint)) prices; // string代表指數名,一個uint代表收盤日期,第二個uint代表收盤價格 function setPrice(string _index, uint _date, uint _price) public{ // 設置某指數某天的收盤價prices[_index][_date] = _price; }function getPrice(string _index,uint _date) public view returns(uint){ // 獲取某指數某天的收盤價return(prices[_index][_date]);}}?
轉載于:https://www.cnblogs.com/huahuayu/p/8624169.html
總結
以上是生活随笔為你收集整理的solidity mapping of mapping的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何禁止Linux内核的-O2编译选项【
- 下一篇: 给初学编程的人的干货