Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can class fields be sealed?

Tags:

c#

oop

field

sealed

In the MSDN C# programming guide, it is mentioned that:

"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?

Thanks.

like image 697
user1510194 Avatar asked Nov 02 '13 15:11

user1510194


1 Answers

That is indeed an error on that page.

The sealed keyword is not applicable to fields.

like image 166
Lasse V. Karlsen Avatar answered Oct 08 '22 23:10

Lasse V. Karlsen