Skip to content

Instantly share code, notes, and snippets.

@wissalHaji
Last active November 14, 2020 13:21
Show Gist options
  • Save wissalHaji/9d770dc2406956711315ebdd0889acfb to your computer and use it in GitHub Desktop.
Save wissalHaji/9d770dc2406956711315ebdd0889acfb to your computer and use it in GitHub Desktop.
Example of storage arrays
// 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