mapping(uint => address) public Players;
can anybody help me how can I delete Players mapping. I wrote a lottery contract and I need to remove this mapping to reuse the contract.
I try this code but It doesn't work
delete Players[playerId];
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this community mapping(uint => address) public Players;
can anybody help me how can I delete Players mapping. I wrote a lottery contract and I need to remove this mapping to reuse the contract.
I try this code but It doesn't work
delete Players[playerId];
Solidity is not like the other languages. You can think of the storage as empty array so even if you have never used a mapping for eg. Players[12334]
its value is not nil/null/nullptr
it is the default value for the type. In your case the default value for address
is the zero address (0x000...
/address(0)
). If you want to delete player it is enough to set it to the zero address.