0

Is it possible to define something like this?

uint256[][] A = [[1], [2], [3, 4, 5], [2, 3]];

Because right now i get this error "Unable to deduce common type for array elements."

2 Answers 2

1

I solved like this, but I would like to hardcode the data

pragma solidity ^0.8.17;

contract ArrayTest {

uint256[][] public test;

//i passed to _testdata [[1], [2], [3, 4, 5], [2, 3]]
function initializeAllVariants(uint256[][] memory _testdata) external {
        test = _test data;
}

}

0

uint256[][] A =[ [1,3,2],[2,4,5],[3,3,3]];

You can declare something like as long as the length of all of the sub-arrays defined in the array are the same

1
  • i do not have the same size of sub-arrays, but i have a certain number of elements.
    – Catalin
    Commented Jan 12, 2023 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.