Created
March 30, 2020 16:41
-
-
Save gwmccubbin/e0e26032466d95ba5dd2273d88889852 to your computer and use it in GitHub Desktop.
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
pragma solidity ^0.6.0; | |
contract MyContract { | |
// Arrays | |
uint[] public uintArray = [1,2,3]; | |
string[] public stringArray = ['apple', 'banana', 'carrot']; | |
string[] public values; | |
uint[][] public array2D = [ [1,2,3], [4,5,6] ]; | |
function addValue(string memory _value) public { | |
values.push(_value); | |
} | |
function valueCount() public view returns(uint) { | |
return values.length; | |
} | |
} |
The code below works fine.
function addArray2D(uint[] memory _array) public {
// append to array2D
array2D.push(_array);
}
function getArray2D(uint index1, uint index2) public view returns(uint) {
// get element at specific index
return array2D[index1][index2];
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I did as exactly to your coding. But when I try to add value to the array2D. It shows error. What did I do wrong on this part? Appreciate for your answer