Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

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

Prepare for the Microsoft Certified Solutions Developer Test with flashcards and multiple choice questions. Each question comes with hints and explanations. Boost your confidence for the exam day!

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 is one key difference between a struct and a class in C#?

  1. A class is a reference type while a struct is a value type

  2. A struct can support inheritance while a class cannot

  3. A struct can declare static members while a class cannot

  4. A class has a smaller memory footprint than a struct

The correct answer is: A class is a reference type while a struct is a value type

The distinction between a struct and a class in C# fundamentally revolves around their types, with the accurate assertion being that a class is a reference type while a struct is a value type. This difference is significant in terms of how they handle memory allocation and data storage. When you create an instance of a class, it is allocated on the heap, and a reference (or pointer) to that memory location is stored. This means when you pass a class instance around in your code, you're passing a reference, which reflects changes made to that instance across all references pointing to it. On the other hand, structs are allocated on the stack, and a copy of the data is created whenever they are passed around. As a result, changes made to a struct instance in one location do not affect the original instance elsewhere in the application. This fundamental difference impacts performance and behavior, especially when dealing with large amounts of data. Considering the other options, while a struct can declare static members, similar capabilities exist for classes as well. In terms of inheritance characteristics, classes can support inheritance for polymorphism and abstraction, which is a key characteristic that structs do not have because they do not participate in inheritance. Finally, class memory footprint varies significantly based on the actual implementation