Recall & Review
beginner
What is a struct in C#?
A struct is a value type that can hold data and related functionality. It is used to create small data structures that have value semantics.
Click to reveal answer
intermediate
How do structs differ from classes in C#?
Structs are value types stored on the stack, while classes are reference types stored on the heap. Structs do not support inheritance but can implement interfaces.
Click to reveal answer
intermediate
Can a struct have a parameterless constructor in C#?
No, structs cannot have explicit parameterless constructors. The compiler provides a default one that initializes all fields to their default values.
Click to reveal answer
beginner
What happens when you assign one struct variable to another?
The entire data is copied. Each struct variable has its own copy of the data, so changes to one do not affect the other.
Click to reveal answer
intermediate
Why might you choose a struct over a class?
Use a struct when you need a small, lightweight object with value semantics, such as points, colors, or complex numbers, to avoid heap allocation and improve performance.
Click to reveal answer
Which of the following is true about structs in C#?
✗ Incorrect
Structs are value types stored on the stack. They do not support inheritance and cannot have explicit parameterless constructors.
What happens when you pass a struct to a method?
✗ Incorrect
Passing a struct to a method copies the entire struct, so the method works with its own copy.
Which keyword is used to declare a struct in C#?
✗ Incorrect
The keyword 'struct' is used to declare a struct in C#.
Can a struct implement interfaces in C#?
✗ Incorrect
Structs can implement interfaces to provide specific behaviors.
Which of these is a reason to use a struct instead of a class?
✗ Incorrect
Structs avoid heap allocation and are good for small data with value semantics.
Explain how structs behave differently from classes in C# regarding memory and copying.
Think about where data is stored and what happens when you assign one variable to another.
You got /4 concepts.
Describe when and why you would choose to use a struct instead of a class in your C# program.
Consider the size and behavior of the data you want to represent.
You got /4 concepts.