Solidity中怎么利用returns函数接收多个值
这篇文章给大家介绍Solidity中怎么利用returns函数接收多个值,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
成都创新互联公司提供高防物理服务器租用、云服务器、香港服务器、成都服务器托管等
函数返回多个值
// 函数可以返回多个值 function multipleReturns() returns(uint a, uint b, uint c) { return (1, 2, 3); }
同时接收所有返回值
function processMultipleReturns() { uint a; uint b; uint c; // 这样来做批量赋值: (a, b, c) = multipleReturns(); }
只接收部分返回值
// 或者如果我们只想返回其中一个变量: function getLastReturnValue() { uint c; // 可以对其他字段留空: (,,c) = multipleReturns(); }
项目中实际碰到问题
function multipleReturns() returns(string memory a, uint b, uint c) { return ("1", 2, 3); } function processMultipleReturns() { string memory a; uint b; uint c; // 这样来做批量赋值: (a, b, c) = multipleReturns(); }
mapping (uint256 => Tree) public dnaToTree; //通过 Dna 获取加密资产详情 function getTreeByDna(uint256 _Dna) public constant returns(string memory treeByDna_user , uint256 treeByDna_dna,string memory treeByDna_treeName, uint64 treeByDna_birthTime, uint256 treeByDna_needFooder, bytes32 treeByDna_status, bool treeByDna_isAdult) { return (dnaToTree[_Dna].user, dnaToTree[_Dna].dna, dnaToTree[_Dna].treeName, dnaToTree[_Dna].birthTime, dnaToTree[_Dna].needFooder ,dnaToTree[_Dna].status ,dnaToTree[_Dna].isAdult); } function getTreeByDna_d(uint256 _Dna) public constant { string memory treeByDna_user; uint256 treeByDna_dna; string memory treeByDna_treeName; uint64 treeByDna_birthTime; uint256 treeByDna_needFooder; bytes32 treeByDna_status; bool treeByDna_isAdult; (treeByDna_user, treeByDna_dna, treeByDna_treeName, treeByDna_birthTime, treeByDna_needFooder, treeByDna_status, treeByDna_isAdult) = getTreeByDna(_Dna); }
关于Solidity中怎么利用returns函数接收多个值就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
网站题目:Solidity中怎么利用returns函数接收多个值
路径分享:http://ybzwz.com/article/igcopi.html