✏️ Explanatory Question

What is a static constructor in X++, and when does it run?

👁 2 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

A static constructor in X++ is defined using:

static void TypeNew()

It is automatically executed:

  • Before any static method call.

  • Before any instance method call.

  • Only once per session.

Important characteristics:

  • Cannot be explicitly called.

  • Cannot accept parameters.

  • Must be marked as static.

  • Used to initialize static fields.

The compiler guarantees that the static constructor runs exactly one time before the class is used.