【Solidity】同一个function同时返回多个值

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract test {
    
    function returnMany()public pure returns(bool,uint){
        return (true,100);
    }

    function returnNamed()public pure returns(bool x, uint y){
        return (false,99);
    }

    function returnAssigned()public pure returns(bool x, uint y){
        x = true;
        y = 1000;
    }

    function destructingAssignments() public pure{
        (bool x, uint y) = returnMany(); //从returnMany的function返回的值进行解构
    }
}

Loading

Facebook评论