const和readonly都是只读的。但是const修饰的变量必须在声明时赋值。readonly修饰的变量可以在声明时或者构造函数里赋值。private const double pi=3.14;class A { private readonly int a; public A(int v) { a=v; } }
时间: 2024-10-01 20:20:55
const和readonly都是只读的。但是const修饰的变量必须在声明时赋值。readonly修饰的变量可以在声明时或者构造函数里赋值。private const double pi=3.14;class A { private readonly int a; public A(int v) { a=v; } }