C# Language Keywords sealed

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

When applied to a class, the sealed modifier prevents other classes from inheriting from it.

class A { }
sealed class B : A { }
class C : B { } //error : Cannot derive from the sealed class

When applied to a virtual method (or virtual property), the sealed modifier prevents this method (property) from being overriden in derived classes.

public class A 
{
    public sealed override string ToString() // Virtual method inherited from class Object
    {
        return "Do not override me!";
    }
}

public class B: A 
{
    public override string ToString() // Compile time error
    { 
        return "An attempt to override"; 
    }
}


Got any C# Language Question?