Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Session length

1 / 20

What cannot be declared in a struct in C#?

Methods

Properties

Static members

In C#, a struct can indeed include methods, properties, and constructors, as well as fields. However, there are specific limitations regarding static members when it comes to structs. While structs can have static members, they cannot have a static constructor. A static constructor is utilized to initialize any static data or to perform a particular action that needs to be performed only once per type rather than once per instance.

Structs are value types in C#, and the design of the C# language restricts structs from having a static constructor because a static constructor cannot be called by an instance of the struct. It is meant for the type itself, and since structs do not support inheritance like classes, the idea of a static constructor alongside struct behaviors does not fit the language's design principles.

Thus, while a struct can declare static fields or methods, the absence of a static constructor is what makes this option the correct answer for what cannot be declared in a struct in C#.

Get further explanation with Examzify DeepDiveBeta

Constructors

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy