What is the difference between static class and singleton?
Murali Poola
Select an image from your device to upload
Static classes and singletons both provide sharing of redundant objects in memory, but they are very different in usage and implementation. Static Class:
You cannot create the instance of static class.
Loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
Static Class cannot have constructor.
we cannot pass the static class to method
We cannot inherit Static class to another Static class in C#.
Singleton:
You can create one instance of the object and reuse it. Singleton instance is created for the first time when the user requested. singleton class can have constructor.
you can create the object of singleton class and pass it to method
Singleton class does not say any restriction of Inheritance.
We can dispose the objects of a singleton class but not of static class