Making a class not inherited

Adding to the PostMan's answer, we can achieve the same by making the Class Constructor Private.

class NotInheritable
    {

        private NotInheritable()
        {
            //making the constructor private
        }
    }

 class Derived : NotInheritable { }

Now the class NotInheritable will not be inheritable, as the compiler will prompt the error:

NotInheritable.NotInheritable() is inaccessible due to its protection level.


sealed is the word you're looking for, and a link for reference

public sealed class MyClass
{

}

And then just create your class as normal, however you won't be able to inherit from it.

You can however still inherit from a different class like so

public sealed class MyClass : MyBaseClass
{

}