ALLINSIGHT

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.”

Explanation:
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

Your email address will not be published. Required fields are marked *