In other languages I can set up the method signature like
cookEgg(boolean hardBoiled = true)
This defaults the parameter hardboiled to true, if I don’t receive a parameter in the method call.
How would I achieve this in C#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
At present, you have to overload the method:
C# 4.0 will add optional arguments – you will be able to write code exactly as in your original sample, and it will work as you’d expect.