Difficulty: Easy
Correct Answer: Sample class Tab1 method
Explanation:
Introduction / Context:
This question examines when the static constructor runs relative to the first access to a type, compared to the invocation of a static method, and how that affects the order of outputs on the console.
Given Data / Assumptions:
Concept / Approach:
In C#, the static constructor executes automatically once, before the first use of the type (first access to any static member). Therefore, referencing Sample.CuriousTab1 triggers the static constructor first, then the static method body runs.
Step-by-Step Solution:
Verification / Alternative check:
Add another call to Sample.CuriousTab1(); you will see the static constructor does not repeat, confirming it runs only once per AppDomain.
Why Other Options Are Wrong:
Common Pitfalls:
Thinking static constructors run at compile time or on every static call; in reality they run once, just before first use of the type.
Final Answer:
Sample class Tab1 method
Discussion & Comments