Skip to content

Commit 190acf1

Browse files
Update sealed.md with sealing methods from Object class (#44196)
* Update sealed.md with sealing methods from Object class It was introduced in C# 10. There is possibility to prevent overriding of ToString() and the rest of Object's virtual methods * Update sealed.md corrected hrefs * Update sealed.md Fixed link to what's-new * Update sealed.md there was still too much '/' backtracking in the whats-new link * Update docs/csharp/language-reference/keywords/sealed.md Co-authored-by: Bill Wagner <[email protected]> --------- Co-authored-by: Bill Wagner <[email protected]>
1 parent b9053c9 commit 190acf1

File tree

1 file changed

+5
-0
lines changed
  • docs/csharp/language-reference/keywords

1 file changed

+5
-0
lines changed

docs/csharp/language-reference/keywords/sealed.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ In the following example, `Z` inherits from `Y` but `Z` cannot override the virt
2727
[!code-csharp[csrefKeywordsModifiers#16](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsModifiers/CS/csrefKeywordsModifiers.cs#16)]
2828

2929
When you define new methods or properties in a class, you can prevent deriving classes from overriding them by not declaring them as [virtual](virtual.md).
30+
When you override a `virtual` member declared in a base type, you can prevent deriving types from overriding them by using sealed keyword as in the following example:
31+
32+
```
33+
public sealed override string ToString() => Value;
34+
```
3035

3136
It is an error to use the [abstract](abstract.md) modifier with a sealed class, because an abstract class must be inherited by a class that provides an implementation of the abstract methods or properties.
3237

0 commit comments

Comments
 (0)