Multiple choice technology programming languages

How does struct differ from class in C#?

  1. Structs cannot be inherited.

  2. Structs are passed by value, not by reference.

  3. Struct is stored on the stack, not the heap.

  4. structs can be inherited

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Structs in C# cannot be inherited from and cannot serve as base classes - they are sealed by nature. While structs are value types (passed by value), that's not the ONLY difference. Option B is a distractor because structs ARE passed by value, but option A is the more fundamental difference. Option D is false because structs CANNOT be inherited.

AI explanation

The marked answer 'Structs cannot be inherited' is a true and defining difference: C# structs are implicitly sealed value types — a struct cannot serve as a base type and cannot derive from another struct or class (it may only implement interfaces), whereas classes support inheritance. Note the item is imperfect as a single-select: 'Structs are passed by value, not by reference' (id 544409) is ALSO a true difference (structs are value types, classes are reference types). Option C ('stored on the stack, not the heap') is the classic oversimplification and is NOT reliably true — a struct that is a field of a class, boxed, or captured lives on the heap. Option D is false. Because the marked answer is a genuinely correct statement, the DB key is defensible, but the question should be tightened (make A and B mutually exclusive) to remove the second valid answer.