Home of the AlmostImplementedException

How to check if a class is static

With the abstract class Type you can get alot of information about anything in C#. But although there are alot of Is… properties, there is no IsStatic.
If you want to know if a class is static you have to use IsAbstract and IsSealed. When both are true then you
have a static class.

To quote Microsoft:
“Do declare static classes as sealed and abstract, and add a private instance constructor, if your programming language does not have built-in support for static classes.”

A abstract class and a static as well can not be instantiated. This is checked with IsAbstract. But abstract alone isn’t enough.
A static class is also sealed, because it can’t be inherited unlike an abstract class, which should inherited.

Share :

Leave a Reply