Tuesday, June 2, 2020

Arrays in Solidity Programming Language.

Arrays

Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional arrays. bytes1, bytes2, bytes3, ..., bytes32 are types for byte arrays. byte is an alias for bytes1. Here is an example that shows generic array syntaxes:


contract sample{
          
       int[] myArray = [0, 0];
       function sample(uint index, int value){
                 myArray[index] = value;
                 int[] myArray2 = myArray;
                 uint24[3] memory myArray3 = [1, 2, 99999];     
                 uint8[2] myArray4 = [1, 2];
         }
 }

Here are some important things you need to know about arrays:

  • Arrays also have a length property that is used to find the length of an array. you can also assign a value to the length property to change the size of the array. However, you cannot resize an array in memory or resize a nondynamic array.
  • If you try to access an unset index of a dynamic array, an exception is thrown.
  • Remember that arrays, structs, and maps cannot be parameters of functions and also cannot be returned by functions.

Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...