在Solidity中设置数组的length属性

时间:2017-03-21 02:32:25

标签: arrays ethereum solidity

设置数组的length属性有什么作用。在大多数其他语言中,length是一个返回arra长度的函数,但在此代码中正在设置struct ledger_t { uint8 WinningNum1; uint8 WinningNum2; uint8 WinningNum3; uint8 WinningNum4; bytes32 ClosingHash; bytes32 OpeningHash; mapping(address=>bet_t) bets; uint Guess4OutOf4; uint Guess3OutOf4; uint Guess2OutOf4; uint Guess1OutOf4; uint PriceOfTicket; uint ExpirationTime; //for eventual refunds only, ~2 weeks after draw announced } ledger_t[] public ledger; //constructor function TheEthereumLottery() { owner = msg.sender; ledger.length = 0; IndexOfCurrentDraw = 0; referral_fee = 90; } 属性。

{{1}}

1 个答案:

答案 0 :(得分:0)

Solidity数组的length属性可用于获取和设置该数组的长度。只需从属性中读取长度:

l = ar.length

并为数组设置新长度只需指定新的长度值:

ar.length = 5

这与实现获取和设置数组长度的特定函数的大多数语言不同。