How to Resolve Error "CS0441: A class cannot be both static and sealed" in C#
The Compiler Error CS0441 is a redundancy error involving class modifiers. The message reads: "'ClassName': a class cannot be both static and sealed".
In C#, a static class is designed to be a container for static members (methods, properties) that does not require instantiation. By definition, a static class cannot be inherited from (it is effectively sealed) and cannot be instantiated (it is effectively abstract).
Because a static class is implicitly sealed by its very nature, adding the sealed keyword explicitly is considered redundant and contradictory to the definition of "static" in the C# language specification. Therefore, the compiler forbids combining these two keywords.
Understanding Static vs. Sealed
-
staticClass:- Cannot be instantiated (
new MyClass()is illegal). - Cannot be inherited from (
class Child : MyStaticClassis illegal). - Can only contain static members.
- Implicitly
sealedandabstract.
- Cannot be instantiated (
-
sealedClass:- Can be instantiated (usually).
- Cannot be inherited from.
- Can contain both static and instance members.
Applying sealed to a static class provides no additional value and implies a misunderstanding of what static means.
Scenario: The Redundant Modifier
This error typically happens when a developer wants to be absolutely sure that no one inherits from their utility class, so they add sealed out of habit, not realizing static already enforces that rule.
Example of error:
// ⛔️ Error CS0441: A class cannot be both static and sealed.
// 'static' already prevents inheritance. 'sealed' is not allowed here.
public static sealed class MathHelpers
{
public static int Add(int a, int b) => a + b;
}
Solution: Choose One Strategy
You must decide what kind of class you are building.
Option A: Pure Utility Class (Use static)
If the class contains only static methods and you never want to create an instance of it, use static.
// ✅ Correct: "static" implies sealed. No one can inherit from this.
public static class MathHelpers
{
public static int Add(int a, int b) => a + b;
}
Option B: Instantiable but Final Class (Use sealed)
If the class holds state (instance fields) and you want to create objects like new User(), but you want to prevent others from subclassing it, use sealed.
// ✅ Correct: "sealed" prevents inheritance, but allows instantiation.
// You generally wouldn't use 'static' here unless the class logic is purely global.
public sealed class UserInfo
{
public string Name { get; set; }
}
Conclusion
CS0441 acts as a grammar check.
- Check the Definition: Are you using
static sealed class? - Remove
sealed: If the class is static,sealedis unnecessary and illegal. - Remove
static: If you intended to make a standard class that simply cannot be subclassed, keepsealedand removestatic.