C# Default Parameter Value
C# Default Parameter Value
In C#, a default parameter value allows you to assign a value to a method parameter so that the caller can omit that argument when calling the method.
🔹 Basic Example
Calling the Method
🔹 Multiple Default Parameters
🔹 Default Values Must Be Last
❌ Invalid:
✔ Correct:
🔹 Default Parameters with Named Arguments
🔹 Default Values and Method Overloading
Instead of writing multiple overloads:
You can use default values:
🔹 Allowed Default Values
✔ Constant values
✔ null
✔ default(type)
🔹 Common Mistakes
❌ Default parameters not at the end
❌ Using non-constant expressions
❌ Conflicts with method overloading
🔹 Summary
✔ Default values make parameters optional
✔ Must be placed at the end
✔ Work well with named arguments
✔ Reduce method overloads
