0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Solidity】(tips)関数内での戻り値の記載方法

Posted at

関数内での戻り値の記載方法が2通りあったので下記します。
ここで、num関数のように、関数の見出しのreturnsの()内に型のみを記載するし、関数内でreturnを用いて値を返す方法が多く見られれます。

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract Sample{
    function num(uint _a, uint _b)internal pure returns(uint, uint){
       return (_a, _b);
    }
}

ここで、exNum関数のように、関数の見出しのreturnsの()内に型及び変数名を記載すれば、関数内でreturnの記載はなしで、記載した変数名に値を代入するのみで関数を実行することができます。

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract Sample{
    function exNum(uint _a, uint _b)internal pure returns(uint number1, uint number2){
        number1 = _a;
        number2 = _b;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?