How to prevent a class from being inherited in C#.NET

How to prevent a class from being inherited in C#.NET?

- The sealed modifier is used to prevent derivation from a class.

- An error occurs if a sealed class is specified as the base class of another class.

- A sealed class cannot be an abstract class.

- Sealed method enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.

Example:
class A
{
   protected virtual void show()
   {
       //Statements
   }
}

class B : A
{
   sealed protected override void shoe()
   {
       //Statements
   }
}
What are generics in C#.NET?
What are generics in C#.NET? - Generic types to maximize code reuse, type safety, and performance....
Use of GetCommandLineArgs() method in C#.NET
What is the use of GetCommandLineArgs() method in C#.NET? - With GetCommandLineArgs() method, the command line arguments can be accessed...
What is the use of System.Environment class in C#.NET?
What is the use of System.Environment class in C#.NET? - The System.Environment class can be used to retrieve information...
Post your comment