【问题标题】:What is the meaning of comma sequence like ,,,,, in Solidity?Solidity 中的 ,​​,,,, 等逗号序列是什么意思?
【发布时间】:2022-11-18 00:06:13
【问题描述】:

我最近遇到了以下 Solidity 函数:

function testHealthFactor() public {
        (, , , , , uint256 healthFactor) = ILendingPool(lendingPool).getUserAccountData(user);
        console.log("health factor", healthFactor);
        assertEq(healthFactor < 1 ether, true);
    }

我对Solidity还不够了解,所以我想知道那5个逗号序列的挖掘是什么?

【问题讨论】:

    标签: solidity


    【解决方案1】:

    Solidity 允许您在一个函数中返回多个值。如果不需要这些值,可以省略它们,并使用, 移至下一个。

    例如:

    function returnStuff() public returns (uint256, uint256) {
       return (1, 3);
    }
    
    ( , uint256 ourNum) = returnStuff();
    // ourNum = 3
    

    【讨论】:

    • 好的,非常感谢@martijn :-)
    • 您是否也知道这种做法是否也会在汽油费消耗方面“优化”合同?
    • 我不是 100% 确定,但由于您使用的变量较少,我可以想象它有助于降低汽油费。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 2015-06-19
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多