Sealed is sealed. As the name suggests, when this keyword modifies a class, the sealing class cannot be inherited. The sealing method will override the methods in the base class, but it cannot be further rewritten in any derived class. When applied to methods or attributes,SealedThe modifier must always be used with override.
That is to say, to use sealed to modify the method, the method to be modified must be the method to rewrite the parent class. Sealed and override are used together. This sealed keyword is the same as the final keyword in Java. The class cannot be inherited, and the method cannot be overwritten. Because interfaces and abstract classes can only be inherited, the sealed keyword cannot be used to modify abstract classes and interfaces. Msdn also explains that the structure is implicitly sealed, which is why the structure cannot be inherited.
Public class person {string name; int age; Public Virtual void sayhello () {console. writeline ("I am person Class Object") ;}} public class Chinese: person {public sealed override void sayhello () // sealed keyword used with override, this method cannot be rewritten by the quilt class {console. writeline ("I am chinesese object") ;}} public sealed Class A: Chinese // This class cannot be inherited. {String school = "gdpu"; // public override void sayhello () {} rewrite error. This member is sealed and cannot be rewritten}