Last active
November 14, 2020 13:21
-
-
Save wissalHaji/9d770dc2406956711315ebdd0889acfb to your computer and use it in GitHub Desktop.
Example of storage arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.7.0; | |
contract A { | |
uint256[] public numbers;// dynamic length array | |
address[10] private users; // fixed length array | |
uint8 users_count; | |
function addUser(address _user) external { | |
require(users_count < 10, "number of users is limited to 10"); | |
users[users_count] = _user; | |
users_count++; | |
} | |
function addNumber(uint256 _number) external { | |
numbers.push(_number); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment