current position:Home>How to judge whether a structure is empty in solidity?

How to judge whether a structure is empty in solidity?

2022-02-03 23:37:43 Q & A of Denglian community

pragma solidity ^0.6.0;pragma experimental ABIEncoderV2;contract Market  {    struct Fruit {        uint amount;    }    uint256[] public fruitId;    mapping (uint256 => Fruit) private _fruits;    function gettotal() public view returns (uint) {        return fruitId.length;    }    function getFruit(uint256 _fruitId) public view returns (Fruit memory) {        return _fruits[_fruitId];    }    function addFruit(uint256 _fruitId) public   {        //require(_fruits[_fruitId]== Market.Fruit(0),"added");  It doesn't seem to work 0 Judge         _fruits[_fruitId]    =  Fruit( 0);        fruitId.push(_fruitId) ;    }}

Add a new id You should judge this fruit Have you added , How to judge this id Is the corresponding structure empty ?






Other answers 1:


Other answers 2:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032337408127.html

Random recommended