Optional Parameter
What are optional parameters
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Princy GuptaRank #1,602 · 982 reputationPosted Mar 19, 2014, 8:04 PM EDT
C# 4.0 has introduced optional parameters for functions and constructors.
Their values don't have to be explicitly specified by the caller. If the parameter has not been specified as an argument by the caller it is given a default value
voidDisplayOutput(string text1, string text2="optional parameter"){Print(text1); Print(text2);}Only last parameter is optional parameterSunny SharmaRank #223 · 11.1K reputationPosted Mar 19, 2014, 8:36 PM EDT
Just to add-on, If you're not passing all the parameters, then optional parameters can be passed only after the required parameters.
Instead of posting it here in Q/A forum, you should post it as a blog.