坚固的阵列声明
大家好,我目前正在学习坚固的性能,并遇到了不同的方式来宣布阵列的坚固性。
uint [2] statearray1 = [uint(1),2];
uint [2] statearray2 = [uint(3),4];
我知道两个数组只能包含未签名的整数,并且大小为2。 我不明白的是UINT(1)和UINT(3) 在默认数组参数旁边声明。
感谢您帮助我澄清这一点。
Hello everyone I am currently learning solidity and came across different ways of declaring arrays in solidity.
uint[2] stateArray1 = [uint(1),2];
uint[2] stateArray2 = [uint(3),4];
I understand both arrays can only contain unsigned integers and have a size of 2.
What I don't understand is the uint(1) and uint(3)
declared beside the default array parameters.
Thank you for helping clarify this for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
uint(1)
明确地将1
的值施加到uint256
的类型(作为uint
,没有指定的长度是uint256
的别名。uint(3)
或通常uint(< n>)
也是如此。这是Remix IDE中包含的JavaScript EVM模拟器的较旧版本的解决方法,在某些情况下,该值处理的值255及以
uint88
(最大值255),因此它错误地显示了类型错误(尝试尝试(尝试)要将uint8
分配到uint256 []
array)中。该问题已经解决,因此现在您不必明确指定该类型:uint(1)
explicitly casts the value of1
to the type ofuint256
(asuint
without the specified length is an alias ofuint256
). Same goes foruint(3)
or generallyuint(<N>)
.This was a workaround for older versions of the JavaScript EVM emulator included in Remix IDE, that in some cases treated values 255 and smaller as
uint8
(max value 255), so it incorrectly showed a type error (trying to assignuint8
into anuint256[]
array). The issue has been fixed, so now you don't have to explicitly specify the type anymore: