【CryptoZombies】lesson1 Chapter 6: Arrays

// Array with a fixed length of 2 elements:
uint[2] fixedArray;
// another fixed Array, can contain 5 strings:
string[5] stringArray;
// a dynamic Array - has no fixed size, can keep growing:
uint[] dynamicArray;

Public Arrays

You can declare an array as public, and Solidity will automatically create a getter method for it. The syntax looks like:

Person[] public people;

Javaと書き方が違うが、基本的には似たような構成。


test

We're going to want to store an army of zombies in our app. And we're going to want to show off all our zombies to other apps, so we'll want it to be public.

1.Create a public array of Zombie structs, and name it zombies.

pragma solidity >=0.5.0 <0.6.0;

contract ZombieFactory {

   uint dnaDigits = 16;
   uint dnaModulus = 10 ** dnaDigits;

   struct Zombie {
       string name;
       uint dna;
   }

   // start here
   Zombie[] public zombies;

}


Words I didn't know
・fixed arrays:固定長配列
・dynamic arrays:可変長配列




この記事が気に入ったらサポートをしてみませんか?