using System;using System.Collections.Generic;using System.Text; namespace __13{ class Program { static void Main(string[] args) { const int a = 12; const string b = "jack"; const int c = a * 2; modify(a, b); Console.WriteLine(a+" "+b); Console.WriteLine(c); } private static void modify(int a, string b) { a = 4; b = "john"; } }} //输出结果是: 12 jack 24 //a b 并没有变,但也不报错 const 字段只能在该字段的声明中初始化。readonly 字段可以在声明或构造函数中初始化。因此,根据所使用的构造函数,readonly 字段可能具有不同的值。另外,const 字段是编译时常量,而 readonly 字段可用于运行时常量,const 字段只能在该字段的声明中初始化。readonly 字段可以在声明或构造函数中初始化。因此,根据所使用的构造函数,readonly 字段可能具有不同的值。另外,const 字段是编译时常量,而 readonly 字段可用于运行时常量,

评论