【发布时间】:2016-04-15 19:29:19
【问题描述】:
下面的声明有什么区别吗(除了const和static readonly的区别)?
public static int foo1 { get; } = 8;
private static readonly int foo2 = 4;
public static int Foo2
{
get { return foo2; }
}
private const int foo3 = 9;
public static int Foo3
{
get { return foo3;}
}
foo1 在幕后发生了什么?和foo2 或foo3 一样吗?
我问foo1,因为我不能用这种语法把它变成const 或readonly,所以我还问它是否真的是一个常量?
【问题讨论】:
标签: c# syntax properties constants readonly