自定义结构体
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
}
Person就是我们自定义的一个新的结构体类型,结构体里面可以存放任意类型的值。
初始化一个结构体
初始化一个storage类型的状态变量。
方法一
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
Person _person = Person(18,101,"liyuechun");
}
方法二
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
Person _person = Person({age:18,stuID:101,name:"liyuechun"});
}
初始化一个memory类型的变量。
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
function personInit() {
Person memory person = Person({age:18,stuID:101,name:"liyuechun"});
}
}
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
}
Person就是我们自定义的一个新的结构体类型,结构体里面可以存放任意类型的值。
初始化一个结构体
初始化一个storage类型的状态变量。
方法一
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
Person _person = Person(18,101,"liyuechun");
}
方法二
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
Person _person = Person({age:18,stuID:101,name:"liyuechun"});
}
初始化一个memory类型的变量。
pragma solidity ^0.4.4;
contract Students {
struct Person {
uint age;
uint stuID;
string name;
}
function personInit() {
Person memory person = Person({age:18,stuID:101,name:"liyuechun"});
}
}