5

I have a function which returns two uint values:

function unclaimedCollateralRewardAndDebt() public view returns(uint, uint)

in most cases I use both returned values but sometime I need only one. Is there a way to ignore one of the returned values like in GoLang?

// getting both values
(uint unclaimedCollateral, uint unclaimedDebt) = unclaimedCollateralRewardAndDebt();
// get only first value
(_, uint unclaimedDebt) = unclaimedCollateralRewardAndDebt();
// get only second value
(uint unclaimedCollateral, _) = unclaimedCollateralRewardAndDebt();

1 Answer 1

7
// get only first value
(, uint unclaimedDebt) = unclaimedCollateralRewardAndDebt();
// get only second value
(uint unclaimedCollateral,) = unclaimedCollateralRewardAndDebt();

should work

1
  • what if there's more than 2 return values? can we ignore the middle one like (uint a,,uint b) ? Commented Mar 25, 2023 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.