Posts

Showing posts from May, 2023

OOPS Concept - Static class and static constructor

This post is about refreshing couple of basis rules/points in respect of OOPS. Considering C# as one of the languages which support OOPS, following points has been described. Let's start wih the concept. A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. You need to call class.method directly like Math.Abs() or Math.Floor(). Creating a static class is basically the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated. Non-Static Class, Static field and constructure, usage like singleton and below: A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file. Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method. Static constructors are also a convenient pl