官术网_书友最值得收藏!

  • Mastering Ethereum
  • Merunas Grincalaitis
  • 139字
  • 2021-06-24 15:01:05

Mappings

Mappings are a special type of variable in the sense that they can hold an endless amount of data. It's like a combination of an array and a struct. You can add elements to it for a set of types:

mapping(string => bool) public validStrings;

Mappings store information as an unlimited array. They work similar to objects in JavaScript, where each key has a value associated and they can be accessed randomly. They don't have a fixed length, nor can you get the length of them, as with arrays, for looping their values. What you must do instead is save the latest updated key of your mapping and go from there.

You can set values for mappings as follows:

validStrings['example'] = true;

In our example, all values of validStrings will be false until you set them to true.

主站蜘蛛池模板: 丰台区| 泌阳县| 塔城市| 汤原县| 宣恩县| 建德市| 齐齐哈尔市| 东海县| 阜宁县| 博乐市| 南召县| 临江市| 云阳县| 长乐市| 财经| 丰都县| 台州市| 保山市| 北辰区| 博罗县| 莎车县| 垣曲县| 浦北县| 开远市| 休宁县| 霍林郭勒市| 武乡县| 灵山县| 修文县| 维西| 炎陵县| 广西| 盐山县| 外汇| 繁峙县| 渑池县| 柘城县| 瑞金市| 高密市| 凤阳县| 碌曲县|