Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 1.65 KB

ca1048.md

File metadata and controls

46 lines (34 loc) · 1.65 KB
title description ms.date ms.topic f1_keywords helpviewer_keywords author ms.author manager ms.subservice monikerRange
CA1048: Do not declare virtual members in sealed types
A public type is sealed and declares a method that is both virtual (Overridable in Visual Basic) and not final. This rule does not report violations for delegate types, which must follow this pattern.
11/04/2016
reference
DoNotDeclareVirtualMembersInSealedTypes
CA1048
DoNotDeclareVirtualMembersInSealedTypes
CA1048
mikejo5000
mikejo
mijacobs
code-analysis
vs-2019

CA1048: Do not declare virtual members in sealed types

Item Value
RuleId CA1048
Category Microsoft.Design
Breaking change Breaking

Cause

A public type is sealed and declares a method that is both virtual (Overridable in Visual Basic) and not final. This rule does not report violations for delegate types, which must follow this pattern.

Note

This rule has been deprecated. For more information, see Deprecated rules.

Rule description

Types declare methods as virtual so that inheriting types can override the implementation of the virtual method. By definition, you cannot inherit from a sealed type, making a virtual method on a sealed type meaningless.

The Visual Basic and C# compilers do not allow types to violate this rule.

How to fix violations

To fix a violation of this rule, make the method non-virtual or make the type inheritable.

When to suppress warnings

Do not suppress a warning from this rule. Leaving the type in its current state can cause maintenance issues and does not provide any benefits.