⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8-5.txt

📁 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告
💻 TXT
字号:
0. 常量与静态只读变量类库(文件名Server.cs)

public class Server
{
        public const string Const = "const";
        public static readonly string Readonly = "readonly";
}

编译输出Server.dll。

1. 客户端(文件名Client.cs,编译选项/r:Server.dll)

public class Client
{
        public static void Main()
        {
                System.Console.WriteLine(Server.Const);
                System.Console.WriteLine(Server.Readonly);
        }
}

执行csc Client.cs编译输出Client.exe.

2. 执行Client.exe,输出如下:

const
readonly

3. 现在把Server.cs里面的两个常量的值都换成大写并重新编译Server.cs(Client.exe不变,仍是引用Server.dll)。
再执行Client.exe,输出会是……什么呢?




const 
READONLY 

const在编译quiz.cs时就静态链接到exe文件中了。 
而readonly则在每次运行quiz.exe时调用consts.dll才解析生成。

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -