solidity学习一

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

contract SimpleStorage {
    uint256 public fnumber;

    // People public person=People({fnumber:2,name:"xiang"});


    struct People{
        uint256 fnumber;
        string name;
    }
    People[] public perple;

    mapping(string=>uint256) public nameToFnumber;

    function store(uint256 _fnumber) public {
        fnumber = _fnumber;
    }
    function retrieve()public view returns(uint256){
        return fnumber;
    }
    function addPerson(string memory _name,uint256 _fnumber)public{
        People memory newPerson=People({fnumber:_fnumber,name:_name});
        perple.push(newPerson);
        nameToFnumber[_name]=_fnumber;
    }


}

 

posted @ 2023-04-18 13:08  黑曼巴后仰  阅读(12)  评论(0编辑  收藏  举报