Practice mode C#

What is a key difference between a class and a struct in C#?

Correct answer A. A class is a reference type, while a struct is a value type copied on assignment

Explanation

Class instances live on the managed heap and variables hold references, so assigning one variable to another shares the same object. Structs are value types, so assignment copies all their fields. Structs cannot inherit from other structs or classes, though they can implement interfaces. They suit small, immutable data such as points or money values.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.