Recall & Review
beginner
What is a return value in a method?
A return value is the result a method sends back to the part of the program that called it. It can be a number, text, or any data type.
Click to reveal answer
beginner
What does a
void method mean in C#?A
void method does not return any value. It just runs some code and finishes without sending anything back.Click to reveal answer
beginner
How do you return a value from a method in C#?
Use the
return keyword followed by the value you want to send back. For example: return 5;Click to reveal answer
intermediate
Can a method have both
void and return a value?No. A method declared as
void cannot return a value. If it returns a value, it must have a matching return type.Click to reveal answer
intermediate
What happens if a method with a return type does not have a
return statement?The program will give a compile-time error because it expects a value to be returned from the method.
Click to reveal answer
What keyword do you use to send a value back from a method?
✗ Incorrect
The
return keyword is used to send a value back from a method.What type of method does NOT return any value?
✗ Incorrect
A
void method does not return any value.Which of these is a valid method header for a method that returns a number?
✗ Incorrect
The method
int GetNumber() returns an integer number.What will happen if a method declared to return
int does not have a return statement?✗ Incorrect
Methods with a return type must have a return statement; otherwise, the compiler shows an error.
Can a
void method use the return keyword?✗ Incorrect
A
void method can use return; to exit early but cannot return a value.Explain the difference between a method that returns a value and a void method.
Think about whether the method sends something back or just runs code.
You got /3 concepts.
Describe what happens if you forget to include a return statement in a method that should return a value.
What does the compiler expect from methods with return types?
You got /3 concepts.