LoginSignup
0
0

Solidityで配列を使う方法(構造体も触れるよ)

Posted at

今回はSolidityで配列を宣言する方法についてまとめようと思います。

宣言方法

uint[] array;

要素数を決めたいときは[]内に要素数を書きます。
また、publicと書くことでSolidityが自動的にgetterメソッドを作ってくれます。

uint[3] public array;

構造体を作って配列にしてみる

構造体宣言

struct Person {
    string name;
    uint age;
}

構造体配列を新たに作成して配列に格納

// 構造体の配列を作成
Person[] public people;

// 新しいPersonを作って、配列に格納する
Person tarou = Person("Tarou", 12);
people.push(tarou);

ぜひご参考に

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0