是否可以使 getFirst10() 工作?将 uint256[100] 内存转换为 uint256[10] 内存似乎是不可能的。
contract Test {
uint256[100] private foo;
function get() external view returns (uint256[100] memory) {
return foo; // Works
}
function getFirst10() external view returns (uint256[10] memory) {
return uint256[10](foo); // Doesn't compile
}
}
我得到的最接近的是上面的尝试,但它失败并出现错误:Error: Explicit type conversion not allowed from "uint256[100] storage ref" to "uint256[10] storage pointer"
我想要做的是有一个函数返回一个大的 uint256[] 存储数组的子切片。有没有办法做到这一点?我是否必须返回 calldata 并复制每个元素?