Solidity-Learning

Solidity 学习笔记

View the Project on GitHub XdpCs/Solidity-Learning

006-不可变变量

背景

通过学习Solidity,然后输出文章检验自己的学习成果Github仓库

欢迎大家关注我的X

基础知识

例子

例子

该例子是如何对不可变变量进行赋值

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

contract Immutable {
    address public immutable MY_ADDRESS;
    uint public immutable MY_UINT;
    uint public immutable MY_LOVE = 1118;
    uint public immutable NO_USAGE;

    constructor(uint _myUint){
        MY_ADDRESS = msg.sender;
        MY_UINT = _myUint;
    }
}

程序解析

address public immutable MY_ADDRESS;
uint public immutable MY_UINT;
uint public immutable MY_LOVE = 1118;
uint public immutable NO_USAGE;
constructor(uint _myUint){
    MY_ADDRESS = msg.sender;
    MY_UINT = _myUint;
}

链接