1

I have a function xyz :

uint256 a;
uint256 b;
function xyz() internal view return(uint256,uint256){
return (a,b);
}

Now, I wish to use the first return value in another function (for eg):

uint256 c;
function abc() public {
c += xyz().0; // c += a is desired
}

What should be the correct syntax.

1 Answer 1

4

In Solidity you can ignore one or all of the returned values by just not assigning them to the variables:

(uint a, ) = xyz();

The code above would only get the first returned value and ignore the second one.

(, uint b) = xyz();

This code would only get the second returned value.

uint256 c;
function abc() public {
 (uint a, ) = xyz();
 c += a;
}

This is how you would do it with your example.

1
  • Thanks, that seems like a very simple solution indeed. Jan 16 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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