Ir al contenido

Sealed class (ARCH712)

Esta página aún no está disponible en tu idioma.

Key dotnet.codequality.sealed-class · Severity info · Category codequality

Sealing classes that are not designed for inheritance clarifies intent, prevents unintended derivation, and lets the JIT optimize method calls.

public class JsonReportFormatter : IReportFormatter
{
public string Format(Report report) => JsonSerializer.Serialize(report);
}
public sealed class JsonReportFormatter : IReportFormatter
{
public string Format(Report report) => JsonSerializer.Serialize(report);
}

Add sealed to classes that are not intended to be derived from.