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.
C# 编译器抱怨以下代码包含new protected member declared in struct. 问题是什么?
new protected member declared in struct
struct Foo { protected Object _bar; }
从MSDN 文档:
A struct cannot be abstract and is always implicitly sealed.
看起来 C# 希望您使用“私有”而不是受保护。
因为这是一个结构,所以它不能被覆盖。似乎 C# 编译器希望像结构这样的密封类型使用“private”关键字而不是“protected”关键字,即使在功能上没有任何区别。改用这个:
struct Foo { private Object _bar; }
结构是隐式密封的,因此您不能以任何方式创建后代,而受保护的修饰符意味着只有此类型的实例和派生类型的所有实例才能访问它。