c# - java中public final static的c#等价物是什么

标签 c# java static final public

在Java中我可以写:

public final static MyClass foo = new MyClass("foo");

在 C# 中是否有任何等价物?

最佳答案

我能想到的 Java final 字段最接近的东西(不完全相同,final has other meanings 也是)是 readonly :

public static readonly MyClass field = new MyClass("foo");

如果您有原始类型(字符串、整数、 boolean 值),您可能希望使用 const 代替。

public const string MAGIC_STRING = "Foo";

关于c# - java中public final static的c#等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1181753/

相关文章:

c# - 接口(interface)泛型类的返回结果

c# - 按位运算符的通用约束

c# - decimal.Parse 中接受的小数的正则表达式

java - CDI 事件及其传播范围

java - 反射的哪些部分表现不佳?

c# - 扫描自定义属性的所有类和方法的最佳实践

java - SQL:多对多解析和交叉实体

c++ - C++ 编译时的静态数组

java - 使用 Spring Security 的静态方法获取当前用户详细信息

c++ - static int 执行了多少次?