10

I'm trying to declare an in-memory array with a fixed length:

uint length = 10;
uint[length] memory priorityList;

However, it just displays this error message:

Invalid array length, expected integer literal

Do I have to do uint[10] memory priorityList; or is there a way I can still use a variable to declare the size?

2 Answers 2

6

As per documentation:
Creating arrays with variable length in memory can be done using the new keyword.
You can use following code snippet to solve your problem.

uint length =10;
bytes memory priorityList= new bytes(length);
14

Generally for an array, you would use uint[] memory list = new uint[](some_size);

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.