Solidity-003 BoolContract.sol
// SPDX-License-Identifier: DataSummer
pragma solidity ^0.8.9;?
?
// This is a Solidity contract named BoolContract
contract BoolContract {?
? ? // This boolean variable is used to store the payment status
? ? bool isPaid = true;?
? ? // This function is used to manage the 'isPaid' boolean variable
? ? // It sets 'isPaid' to false and returns the updated value, which will be false
? ? function manageBool() public returns (bool) {?
? ? ? ? isPaid = false;?
? ? ? ? return isPaid; //returns false?
? ? }?
? ? // This function is used to demonstrate converting 'isPaid' (boolean) to 'uint8' (unsigned integer)
? ? // It sets 'isPaid' to false and returns the constant value 10 as a 'uint8' type
? ? // The commented line below would cause an error because 'isPaid' cannot be directly converted to 'uint8'
? ? function convertToUint() public returns (uint8) {?
? ? ? ? isPaid = false; ? ? ??
? ? ? ? return 10;
? ? ? ? // return uint8(isPaid); //error?
? ? }?
} ??
?
//Deploy screenshot show:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!