可以在C#中创建一个默认情况下所有字段和属性都是const的类吗?
public class foo : const /* or readonly */
{
public int baa = 3;
}
答案 0 :(得分:0)
不,不是。
您可以使类静态,但强制所有成员都是静态的。
例如:
public static class Constants
{
public const int SomeId = 123;
public const string SomeName = "foo";
public static readonly DateTime myDateTime = new DateTime();
public string notConstant = "test"; //does not compile
}