Soldity0.8.0-函数返回值

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.7;

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

    function named() public pure returns (uint x, bool b) {
        return (1, true);  //可以写个隐式返回
    }

    function assigned() public pure returns (uint x, bool b) {
        x = 1; 
        b = true;
    }

    function destructingAssigments() public pure {
        (uint x, bool b) = returnMany();
        (, bool _b) = returnMany(); //不需要赋值的变量就不要赋值,可以节省gas费
    }
    
}

 

posted @ 2022-07-26 15:33  ZaleSwfit  阅读(27)  评论(0编辑  收藏  举报