Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for your Microsoft Certified Solutions Developer (MCSD) exam with flashcards and multiple choice questions. Each question includes hints and explanations to help you succeed. Get ready for your exam!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What cannot be declared in a struct in C#?

  1. Methods

  2. Properties

  3. Static members

  4. Constructors

The correct answer is: 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#.