How does struct differ from class in C#?
-
Structs cannot be inherited.
-
Structs are passed by value, not by reference.
-
Struct is stored on the stack, not the heap.
-
structs can be inherited
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.
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.