Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

sealed: practical reference

sealed: practical reference: sealed prevents inheritance of a class or any further override of a member.

Version: C# language; verified against C# 14 reference

Syntax

sealed /* grammar-specific form */

sealed prevents inheritance of a class or any further override of a member.

Use it when an invariant is not designed for extension or an implementation must stay closed.

It is not a substitute for private and does not make objects immutable.

A sealed class cannot be abstract; sealed override requires an inherited virtual member.

The complete program actually uses sealed; its exact expected stdout is 3.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

Console.WriteLine(new Final().Value); sealed class Final { public int Value => 3; }

Result

3

The complete program actually uses `sealed`; its exact expected stdout is `3`.

Sources