0
contract StorageFactory {

    SimpleStorage[] public simpleStorageArray;

    function createSimpleStorageContract() public {
        SimpleStorage simpleStorage = new SimpleStorage();
        simpleStorageArray.push(simpleStorage);
    }

    function get(uint256 _position) public view returns(uint256) {
        return simpleStorageArray(_position);     
    }
}

enter image description here

I know that solidity creates getter functions by default, but I wanna know the code that goes behind.

2 Answers 2

1

simpleStorageArray is an array not a function so you want to use square brackets:

 simpleStorageArray[_position];   
0

you can get single entry or full array at one time.

function get(uint256 _position) public view returns(uint256) {

    return simpleStorageArray[_position];     

}

function getFull() public view returns(uint256[] memory _array) {

    return simpleStorageArray;     

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.