-
Hi All, I am new here. I have a question about when to use ( ) and [ ] Example of code below: //// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract SimpleStorage {
struct person {
string personName;
uint256 personNum;
}
person [] public getPerson ;
mapping (string=>uint256) public personToNum;
function storePerson (string memory _storePersonName, uint256 _storePersonNum) public {
getPerson.push (person(_storePersonName, _storePersonNum));
personToNum[_storePersonName] = _storePersonNum;
}
} For this line: Why is it using [ ] and not ( )? Many thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @solarwhale with this context... set on this index -> personToNum[_storePersonName]= _storePersonNum; <- this value. I hope this info might help. |
Beta Was this translation helpful? Give feedback.
Hello @solarwhale
Each language has it's own conventions for using some symbols., but they are common conventions so...
()
is usually used to refer to function calls,[]
is usually used to refer to numeric/contextual index on data types like arrays.with this context...
set on this index -> personToNum[_storePersonName]= _storePersonNum; <- this value.
I hope this info might help.