Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
public struct Char { public const char MaxValue = (char)0xffff; public const char MinValue = '\0'; }
为什么不将这些字段设为静态?为什么它总是为每个字符分配额外的内存,而这两个值是永久的?
编辑:我不知道我怎么能隐含地忘记静态!
const 字段是隐式静态的。从规范的第 10.4 节:
即使常量被认为是静态成员,常量声明 既不需要也不允许静态 修饰符。同一修饰符在常量声明中多次出现是错误的。
因为它们是静态的。
常量字段是隐式静态的。