O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

static Constructors

As opposed to an instance constructor, a static constructor of a class cannot be called explicitly in the source code. Instead, it is called automatically by the runtime sometime between the start of the program and the instantiation of the first object of the class. The static constructor is declared by writing the static keyword in front of the name of the class and by ending the line with empty parentheses (see Syntax Box 13.3). The statements are positioned in a block after this header.

There are a couple of notable differences between the declaration of a static constructor and an instance constructor. First, because the static constructor can only be accessed by the runtime, it makes no sense to specify an access modifier. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required