简体   繁体   English

课堂领域可以密封吗?

[英]Can class fields be sealed?

In the MSDN C# programming guide , it is mentioned that: MSDN C#编程指南中 ,提到:

"A class member, method, field , property, or event, on a derived class that is overriding a virtual member of the base class can declare that member as sealed." “覆盖基类的虚拟成员的派生类上的类成员,方法, 字段 ,属性或事件可以将该成员声明为已密封。”

I understand the above statement for methods, properties and events, but how is the above statement valid for fields of a class? 我理解上面的方法,属性和事件的声明,但上面的语句如何对类的字段有效? I tried this in a program and verified that a field cannot be virtual and hence cannot be overridden. 我在一个程序中尝试了这个并验证了一个字段不能是虚拟的,因此不能被覆盖。 So how can it be sealed then? 那怎么能被密封呢? And if it cannot, should the above statement from the MSDN reference have left out mention of field? 如果它不能,那么来自MSDN参考的上述声明是否应该省略提及字段?

Thanks. 谢谢。

That is indeed an error on that page. 这确实是该页面上的错误。

The sealed keyword is not applicable to fields. sealed关键字不适用于字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM