Recall & Review
beginner
What are named arguments in C#?
Named arguments allow you to specify the name of the parameter when calling a method, so you can pass arguments in any order and improve code readability.
Click to reveal answer
beginner
How do named arguments improve code readability?
By explicitly naming parameters in method calls, it becomes clear what each argument represents, making the code easier to understand without looking at the method definition.
Click to reveal answer
intermediate
Can you mix named and positional arguments in a method call?
Yes, but positional arguments must come before any named arguments in the call.
Click to reveal answer
beginner
What happens if you use a wrong parameter name in a named argument?
The compiler will show an error because the parameter name does not match any parameter in the method definition.
Click to reveal answer
beginner
Example: How to call a method with named arguments?
void PrintInfo(string name, int age) { Console.WriteLine($"Name: {name}, Age: {age}"); }You can call it like this:
PrintInfo(age: 30, name: "Alice");This prints: Name: Alice, Age: 30
Click to reveal answer
What is the correct way to use named arguments in C#?
✗ Incorrect
Named arguments use the syntax paramName: value when calling a method.
Can you place positional arguments after named arguments in a method call?
✗ Incorrect
In C#, positional arguments must come before named arguments in a method call.
What error occurs if you use a wrong parameter name in a named argument?
✗ Incorrect
The compiler will show an error if the parameter name does not exist.
Why use named arguments?
✗ Incorrect
Named arguments let you specify arguments in any order and make code easier to read.
Which of these calls is valid if the method is void Foo(int x, int y)?
✗ Incorrect
Named arguments use colon (:), not equals (=), and positional arguments must come first.
Explain what named arguments are and how they help when calling methods in C#.
Think about how naming parameters in calls can make code clearer.
You got /3 concepts.
Describe the rules for mixing positional and named arguments in a method call.
Consider the order of arguments when calling a method.
You got /3 concepts.