Recall & Review
beginner
What happens when you pass a value type to a method in C#?
A copy of the value is passed to the method. Changes inside the method do not affect the original variable.
Click to reveal answer
intermediate
How can you make a method modify the original value type variable passed to it?
Use the
ref or out keyword to pass the value type by reference, allowing the method to modify the original variable.Click to reveal answer
intermediate
Explain the difference between passing a value type normally and passing it with
ref.Passing normally sends a copy, so changes inside the method don't affect the original. Passing with
ref sends the actual variable, so changes inside the method affect the original.Click to reveal answer
beginner
What is a value type in C#? Give examples.
Value types store data directly. Examples include
int, double, bool, and struct.Click to reveal answer
beginner
Why might passing value types by value be beneficial?
It protects the original data from accidental changes inside methods and can improve safety and predictability of code.
Click to reveal answer
What is passed to a method when you pass a value type without
ref or out?✗ Incorrect
Passing a value type normally sends a copy of the value to the method.
Which keyword allows a method to modify the original value type variable?
✗ Incorrect
The
ref keyword passes the variable by reference, allowing modification.If you want a method to output a new value through a parameter, which keyword should you use?
✗ Incorrect
The
out keyword is used to output a value from a method parameter.Which of these is NOT a value type in C#?
✗ Incorrect
Classes are reference types, not value types.
What happens if you change a value type parameter inside a method when passed by value?
✗ Incorrect
Only the copy inside the method changes; the original variable remains unchanged.
Describe how passing value types to methods works in C#. Include what happens to the original variable.
Think about whether the method gets the actual variable or a copy.
You got /3 concepts.
Explain the difference between passing a value type with and without the
ref keyword.Consider how changes inside the method affect the original variable.
You got /3 concepts.