In this article, you will learn about Constructor in C# language.
A constructor is a special type of method of a C# class which invokes automatically when a new instance of a class is created. Constructor is used in object initialization and memory allocation of the class. Constructor is used to initialize private fields and their values of the class. A constructor can be overloaded. When we don’t create constructor for the class, the compiler automatically create a default constructor for the class. Constructor name is always same of the class name.
When to use static constructors Static constructors are very useful when you create wrapper classes for unmanaged code. You can also use it when class is using log file and constructor is used to write entries.
Pattern Matching in C#