2020.코딩일지
[solidity] struct구조체 (feat.솔리디티깨부수기) 본문
728x90
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract lec16 {
struct Character { //나만의 타입 구조체 struct
uint256 age;
string name;
string job;
}
mapping(uint256 => Character) public CharacterMapping;
Character[] public CharacterArray;
//필수파라미터 입력 / returns에
//..왜가스비가 안드는거지?
function createCharacter(uint256 _age, string memory _name, string memory _job) pure public returns(Character memory) {
return Character(_age, _name, _job);
}
function createCharacterMapping(uint256 _key, uint256 _age, string memory _name, string memory _job) public {
CharacterMapping[_key] = Character(_age, _name, _job);
}
function getCreagteMapping(uint256 _key) public view returns(Character memory) {
return CharacterMapping[_key];
}
//Array는 인덱스가 자동생성되니까 키값이 없는것.
function createCharacterArray(uint256 _age, string memory _name, string memory _job) public {
CharacterArray.push(Character(_age,_name,_job)); //구조체를 push
}
function getCharacterArray(uint256 _index) public view returns(Character memory) {
return CharacterArray[_index];
}
}
'Block Chain' 카테고리의 다른 글
[solidity] error/try-catch문 (feat.솔리디티깨부수기) (0) | 2022.12.05 |
---|---|
[solidity] if문/반복문/continue와break/equal (feat.솔리디티깨부수기) (0) | 2022.12.05 |
[solidity] mapping/array (feat.솔리디티깨부수기) (11) | 2022.11.29 |
[solidity] event/indexed/super (feat.솔리디티깨부수기) (0) | 2022.11.29 |
[solidity] instance(분신)-constructor/상속/overriding (feat.솔리디티깨부수기) (0) | 2022.11.28 |
Comments