Python Optional Parameters, Named Arguments & out/ref
C# offers powerful parameter capabilities: optional parameters with default fallback values, named arguments for clarity at the callsite, and out/ref keywords for returning multiple values and passing by reference.
"Optional parameters are like a food delivery app where napkins and sauce default to "yes" unless you specifically override them. Named arguments are like labeling every item in your grocery order so nobody confuses the flour with powdered sugar."
Deep Dive: How It Works
Optional Parameters: static void Log(string msg, string level = "INFO") { ... } (level defaults to "INFO" if omitted).
Named Arguments: Log(level: "ERROR", msg: "Database timeout"); (improves readability for methods with many parameters).
out Parameters: Allows a method to return multiple values: static bool TryDivide(int a, int b, out int result) { ... }.
ref Parameters: Passes variable by reference, modifying the caller's original variable directly.
Syntax Blueprint
// Optional Parameter
static void Connect(string host, int port = 8080) { }
// out Parameter
static void GetCoords(out int x, out int y) {
x = 10; y = 20;
}Default parameter values and multi-value out parameters.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Placing optional parameters before required parameters: void Test(int a = 5, int b)Why it happens: Not knowing the ordering rule.
How to fix: Always place optional parameters at the end: void Test(int b, int a = 5).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Create a greeting with default title
Write static void Greet(string name, string title = "Guest") that prints "Welcome, {title} {name}!".
In Main(), call Greet("Alex") without providing the second argument.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.