I need explanation on this array. #6653
-
contract SimpleStorage { struct People { // A list of variable inside an object in solidity they get indexed automatically. People[] public people;
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Lets Explain it down.. And then you have allocating a memory space in name of People , In that you can store both favoriteNumber & name . And this Function passes two parameters 1st is _name that stores to the uint256 _favouriteNumber & 2nd parameter is stores in string memory _name. And finally we push the newPerson (newly stored ones) into the array of People[] public people;. |
Beta Was this translation helpful? Give feedback.
Lets Explain it down..
Now the struct People contains the uint256 favouriteNumber; string name; . So now People becomes user defined data type so we can store our favoriteNumber & name.
And then you have allocating a memory space in name of People , In that you can store both favoriteNumber & name . And this Function passes two parameters 1st is _name that stores to the uint256 _favouriteNumber & 2nd parameter is stores in string memory _name.
And finally we push the newPerson (newly stored ones) into the array of People[] public people;.
Now if you call 0 index position, the passed arguments in that function that displays.