C# Static Constructor

tutorial and example
tutorial and example

In C#, static constructor is the one which is used to initialize static fields. It can also be used to do the task which needs to be done once only. It is invoked automatically when a constructor is called or any static filed is referenced.

  1. We can’t apply any modifier to static constructor.
  2. It can’t be called explicitly.

Let’s see an example of static constructor:

C# Static Constructor Example

Output