# solidity 基础语法学习

By [阿拉斯加的狗](https://paragraph.com/@arych) · 2022-02-13

---

    pragma solidity ^0.4.16;
    
    contract helloworld {
    
        string Myname = "Test";
    
        function getName() public view returns(string) {
            return Myname;
        }
    
        function changeName(string _newName) public {
            Myname = _newName;
        }
    
        function pureTest(string _name) public pure returns(string) {
            return _name;
        }
    }
    

\`view / pure 的区别

view的作用和constant一模一样，可以读取状态变量但是不能改；pure则更为严格，pure修饰的函数不能改也不能读状态变量，否则编译通不过。 solidity的语法结束语句都以"' ; " 结束

contract 后面跟上的合约可以理解为一个class

函数都需要有状态表明 比如" public;\`

---

*Originally published on [阿拉斯加的狗](https://paragraph.com/@arych/solidity)*
