uint[8] array1;
bytes1[5] array2;
address[100] array3;
uint[] array4;
bytes1[] array5;
address[] array6;
bytes array7;
uint[] memory array8 = new uint[](5);
bytes memory array9 = new bytes(9);
array8[0] = 1;
array8[1] = 3;
array8[2] = 4;
length: Array長度 push: 在最後加0 push(x): 在最後加x pop: 移除Array最後一個字
struct Student{
uint256 id;
uint256 score;
}
給Struct賦值有4種方法
- 在function中創建一個storage的struct引用
function initStudent1() external{
Student storage _student = student; // assign a copy of student
_student.id = 11;
_student.score = 100;
}
- 直接引用
function initStudent2() external{
student.id = 1;
student.score = 80;
}
- Constructor
// 方法3:构造函数式
function initStudent3() external {
student = Student(3, 90);
}
- Key Value
function initStudent4() external {
student = Student({id: 4, score: 60});
}