我可以在混音IDE中写吗?

发布于 2025-01-27 19:11:43 字数 277 浏览 4 评论 0原文

我制作了地址类型的动态数组变量, ie,

address payable[] public participant;

这是以下以及为什么写的正确

uint payable[] public participant;

方法

uint[] payable public participant;



enter code here

I made a dynamic array variable of address type, i.e.,

address payable[] public participant;

which one is the correct way to write in the following and why,

uint payable[] public participant;

or

uint[] payable public participant;



enter code here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟月 2025-02-03 19:11:43

地址及其扩展<代码>地址应付,它允许您使用本机transfer()方法将ETH发送到此地址。

由于该类型被称为地址应付,因此您可以通过在类型名称之后附加[]表达式来制作此类型的数组。

没有付款扩展到uint。如果您的目标是定义要发送的金额,则可以存储在常规uint中。

pragma solidity ^0.8;

contract MyContract {
    address payable[] public participants;

    function foo() public {
        uint amount = 1; // 1 wei
        for (uint i = 0; i < participants.length; i++) {
            participants[i].transfer(amount);
        }
    }
}

There's address and its extension address payable, which allows you to use the native transfer() method to send ETH to this address.

Since the type is called address payable, you can make an array of this type by appending the [] expression after the type name.

There's no payable extension to uint. If your aim is to define an amount to be sent, that can be stored in a regular uint.

pragma solidity ^0.8;

contract MyContract {
    address payable[] public participants;

    function foo() public {
        uint amount = 1; // 1 wei
        for (uint i = 0; i < participants.length; i++) {
            participants[i].transfer(amount);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文